-4

I am customizing my nag bar button in iOS7 and I am using the following code:

// Customizing the NavBar Buttons
UIImage * btHome = [[UIImage imageNamed:@"Home.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 3, 0, 3)];

[[UIBarButtonItem appearance] setBackgroundImage:btHome forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];

It is working, but the view shows my home button with the button text over it, I do not want the text to show.

What else do I need to do to remove the text?

What I have is shown here:

enter image description here

rmaddy
  • 314,917
  • 42
  • 532
  • 579
LilMoke
  • 3,176
  • 7
  • 48
  • 88
  • 2
    I don't understand the question. Just don't set the text? – Mick MacCallum Nov 15 '13 at 12:41
  • LOL, yes, I tried that, maybe I am tired, been up awhile, but if I clear the text in IB the button does not show and if I use self.title=@""; or self.parentViewController.text=@""; the text still shows in both iOS 6 and iOS 7. – LilMoke Nov 15 '13 at 12:44

3 Answers3

0

Try to set

1) text color on a bar button item through appearance

2) use setImage: instead of setBackgroundImage: and do not use resizable image

hybridcattt
  • 3,001
  • 20
  • 37
0

Try with this code. May be it will help you.

UIImage *faceImage = [UIImage imageNamed:@"back_arrow.png"];
UIButton *yourbutton = [UIButton buttonWithType:UIButtonTypeCustom];
yourbutton.bounds = CGRectMake( 10, 0, faceImage.size.width, faceImage.size.height );
[yourbutton addTarget:self action:@selector(handleBack:) forControlEvents:UIControlEventTouchUpInside];
[yourbutton setImage:faceImage forState:UIControlStateNormal];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:yourbutton];
self.navigationItem.leftBarButtonItem = backButton;
Pradhyuman sinh
  • 3,936
  • 1
  • 23
  • 38
0

Sets the back button title offset for given bar metrics

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
andyleehao
  • 2,412
  • 1
  • 15
  • 8
  • This solution works sort of, but it does not change the frame of the back button's title, causing alignment issues on smaller screens. – Morkrom Aug 03 '15 at 22:46