user6014500
user6014500

Reputation:

Title in navigation bar too long on smaller screens; set font sizes for different screen sizes?

I made an iOS app. One view has a web view and a navigation bar. I've trouble with the navigation bar. On iPhone 6s the title in the navigation bar is "This is my app!". But on iPhone 5s the title in the navigation bar is "This is my a…". It's because the iPhone 5s screen is't as wide as the iPhone 6s plus screen, so my header is too long.

Is there a possibility to auto shrink the text or set an own font size or other header for iPhone 5s (and other devices)?

I googled nearly all day but could't find any helpful hint. Does anybody have an idea? Please help me!

Here's a screenshot from iPhone 5s: link

Upvotes: 2

Views: 740

Answers (3)

Kamlesh Shingarakhiya
Kamlesh Shingarakhiya

Reputation: 2777

Try This

UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, YOUR_WIDH, YOUR_HEIGHT)];
lbl.textAlignment=NSTextAlignmentCenter;
lbl.backgroundColor=[UIColor clearColor];
lbl.font=[UIFont fontWithName:@"FONT_NAME" size:FONT_SIZE];
lbl.textColor=[UIColor whiteColor];
lbl.text=@"YOUR_TITLE";
self.navigationItem.titleView=lbl;

Hope this helps.

Upvotes: 0

Yunus Eren Güzel
Yunus Eren Güzel

Reputation: 3088

Try this:

label.adjustsFontSizeToFitWidth = true

Also you can try this too:

label.adjustsLetterSpacingToFitWidth = true

Upvotes: 1

HardCoderMan
HardCoderMan

Reputation: 41

You could use the following example.

NSDictionary *size = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Arial" size:17.0], NSFontAttributeName, nil];

UINavigationController* navigationController = [self navigationController];
[navigationController.navigationBar setTitleTextAttributes:size];

Upvotes: 0

Related Questions