0

I've a UIButton that has a custom FONT for the titleLabel attribute.

For some reason on iOS 6.0 it shows only half of the title. I tried increasing the height of the title. but that didn't work.

What am i missing?

Is this my only option?

btn.titleLabel.font = [UIFont fontWithName:@"Frutiger95-UltraBlack" size:17];

enter image description here

This is how it should look (minus the color change)

enter image description here

Community
  • 1
  • 1
Jonathan Thurft
  • 4,087
  • 7
  • 47
  • 78
  • how should it look normally? – holex Oct 13 '13 at 16:57
  • 1
    This may be related to a problem I already experienced with custom fonts. See here: http://stackoverflow.com/questions/9015317/custom-uifont-baseline-shifted – Cyrille Oct 13 '13 at 16:59
  • Once again, please don’t use the cocoa tag for your Cocoa Touch questions. The correct tag is cocoa-touch. –  Oct 14 '13 at 02:06

2 Answers2

0

Single line labels have a low content compression resistance priority on the vertical axis. So when you increase the font size, they don't increase the height of their intrinsicContentSize. Setting the compressionResistancePriority to UILayoutPriorityDefaultHigh or UILayoutPriorityRequired should fix it.

[btn.titleLabel setContentCompressionResistancePriority:UILayoutPriorityRequired
                                                forAxis:UILayoutConstraintAxisVertical];

I think updating the label is enough, but you may need to increase the priority on the button itself as well.

[btn setContentCompressionResistancePriority:UILayoutPriorityRequired
                                      forAxis:UILayoutConstraintAxisVertical];
Fruity Geek
  • 7,351
  • 1
  • 32
  • 41
  • 1
    It did not work. I can increase the size and it works fine with a system font. It just gets cut off when I use a custom font on ios 6.0. also font size has no relevance. I can try any size with the custom font and it wouldnt work – Jonathan Thurft Oct 13 '13 at 16:34
0

I think you need to set button title nil, then make your own custom UILabel and add that label on your button like my example given below-

UILabel *lblloginbtntitle=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, btnLogin.frame.size.width, btnLogin.frame.size.height)];
lblloginbtntitle.text=NSLocalizedString(@"Login", nil);
lblloginbtntitle.textAlignment=NSTextAlignmentCenter;
lblloginbtntitle.textColor=[UIColor whiteColor];
lblloginbtntitle.font=[UIFont fontWithName:@"AvenirNextLTPro-Regular" size:20];
[btnLogin addSubview:lblloginbtntitle]; 
[btnLogin setTitle:@"" forState:UIControlStateNormal]
Anuj Kumar Rai
  • 666
  • 1
  • 6
  • 17