ASH ASH - 10 months ago 42
iOS Question

How do i remove text from back button on navbar within Xcode?

I set an arrow custom image to navigation bar by adding the following code in app delegate, it works but now im looking to remove the text completely for back button.

UIImage * backButtonImage = [UIImage imageNamed: @"BackButtonGrey.png"];
backButtonImage = [backButtonImage stretchableImageWithLeftCapWidth: 15.0 topCapHeight: 30.0];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage: backButtonImage forState: UIControlStateNormal barMetrics: UIBarMetricsDefault];


I just did it like this, worked fine for me :-)

UIImage *backButtonImage = [UIImage imageNamed:@"navigationBarBack.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];

[backButton setImage:backButtonImage

backButton.frame = CGRectMake(0, 0, backButtonImage.size.width, backButtonImage.size.height);

[backButton addTarget:self

UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = backBarButtonItem;