HelloWorld
HelloWorld

Reputation: 7286

How do I have a UIBarButtonItem title with a line break?

In the iPhone music app the right UIBarButtonItem title is "Now Playing" (on two lines). I want to do something similar. How can I make the title two lines?

   UIBarButtonItem *nowPlayingButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Now Playing", @"button in navigationbar right") style:UIBarButtonItemStyleBordered target:self action:@selector(showNowPalyView)];

enter image description here

Upvotes: 0

Views: 1782

Answers (2)

nsgulliver
nsgulliver

Reputation: 12671

It depends on what you are using as the title, in general the new line character does the job.

 NSString   *titleStr=@"Now\nPlaying";

If you are using UIButton or UIlabel then you have to set the lines accordingly

In case you are using custom button out there

[titleButton.titleLabel setLineBreakMode:UILineBreakModeWordWrap];  // will set the line break mode

[titleButton setTitle:titleStr forState:UIControlStateNormal];

Upvotes: 2

iPatel
iPatel

Reputation: 47099

Best way is Add UILabel to UIBarButtonItem and use label.numberOfLines = 0;

Upvotes: 0

Related Questions