Justin Galzic
Justin Galzic

Reputation: 3971

Setting truncation mode for UINavigation title text

I want to configure the truncation mode for the text that appears in UINavigationItem.

I've come across a couple of different solutions of configuring the font size but not sure how to make use of the UILineBreakModeHeadTruncation that exists on NSString.

How I've been able to configure the font size:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
[label setFont:[UIFont boldSystemFontOfSize:16.0]];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setText:self.title];
[self.navigationController.navigationBar.topItem setTitleView:label];
[label release];

(Based on the recommendation from here)

If I call this in loadView or viewDidLoad, it seems to work but outside of that method, after the view has been loaded, it doesn't seem to work. Not sure why though.

Upvotes: 1

Views: 2032

Answers (1)

Jeremy Fuller
Jeremy Fuller

Reputation: 3401

What have you tried, and what's not working? You should be able to do:

label.lineBreakMode = UILineBreakModeHeadTruncation;

Or to wrap to multiple lines:

label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;

Upvotes: 2

Related Questions