I have try to add a two line title bar in UINavigationController
I want to adjust font size automatically set according to string length.My String max size goes to 60. I have try to implemented through following code
UILabel *bigLabel = [[UILabel alloc] init];
bigLabel.text = @"1234567890 1234567890 1234567890 1234567890 1234567890 123456";
bigLabel.backgroundColor = [UIColor clearColor];
bigLabel.textColor = [UIColor whiteColor];
bigLabel.font = [UIFont boldSystemFontOfSize:20];
bigLabel.adjustsFontSizeToFitWidth = YES;
bigLabel.clipsToBounds = NO;
bigLabel.numberOfLines = 2;
bigLabel.textAlignment = ([self.title length] < 10 ? NSTextAlignmentCenter : NSTextAlignmentLeft);
[bigLabel sizeToFit];
self.navigationItem.titleView = bigLabel;
It didn't work for me can you help me please. I have to made this for iPhone and iPad screen
thanks to @TheTiger for such a solution.
I have edited his answer according my requirement. so here is my answer
Just set
setNumberOfLines:
0 ofUILabel
. See the example below.Set Left and Right
UIBarButtonItems
- you can add them.Also decrease the
FontSize
ofLabel
. It is 12 in this case. And it will look like this:For the extended question:
Just make some changes in previous code -
Note: You can't use
adjustsFontSizeToFitWidth:
property ofUILabel
, because it doesn't work forsetNumberOfLines:0
in your case you will have to handle it withif
condition.This is method for set
fontSize
OfUILabel
according to itswidth
.