Reputation: 3921
I'm creating a custom UIBarButtonItem, like so:
UIImage *originalImage = [UIImage imageNamed:@"button"];
UIImage *buttonImage = [originalImage stretchableImageWithLeftCapWidth:10 topCapHeight:5];
UIButton *toolbarB = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 65, 29)];
[toolbarB setTitle:title forState:UIControlStateNormal];
[toolbarB.titleLabel setFont:[UIFont fontWithName:kLatoBold size:17.0f]];
[toolbarB setBackgroundImage:buttonImage forState:UIControlStateNormal];
[toolbarB addTarget:target action:selector forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbarB];
Depending on which of my custom fonts I use, after inserting my UIBarButtonItem into my controller's navigationItem, I get one of the results below.
Why does the button text in the second result "float" higher than it is supposed to? The first button looks great, but the second one positions the text in an unnatural fashion... Could it be a problem with my font?
Button Text Displaying Properly
Annoying, Floating Button Text that is Too High!
Upvotes: 3
Views: 313
Reputation: 2210
It happens for some fonts, I don't know why, but I can suggest you to use UIEdgeInsets
to push your text down a bit. I guess you cannot fix your font, so;
Here is a link for a similar solution; Aligning text and image on UIButton with imageEdgeInsets and titleEdgeInsets
Upvotes: 1