0

Can anyone suggest how to effective achieve what appears in the picture below?

Expected outcome with title

To summarize:

  1. The titleView is aligned close to the Back button. I tried by setting the frame of the titleView but it only changes within a fixed bounds
  2. The title is multiline and left aligned. I guess this can be achieved just by setting the .textAlignment and numberOfLines properties of, presumably, the title label
  3. The title.top seem to be aligned with backButton.top
  4. The gray line below the title wouldn't be the topLayoutGuide as it seems customizable at least in its length
  5. The navigation bar itself is more than 64p - the default height, and can possibly be calculated?

So far, I have tried adding a UIView with a UILabel subview to the navigation bar and it sort of works but looks like

What is achieved so far

unspokenblabber
  • 1,567
  • 1
  • 11
  • 19

1 Answers1

0

You can try below code.

objective c

UILabel *lblTitle = [[UILabel alloc] init];
lblTitle.textColor = [UIColor blackColor];
lblTitle.text=@"This is a multiline string for the navBar details";
lblTitle.font=[UIFont systemFontOfSize:16];
lblTitle.frame = CGRectMake(0, 0, 150, 50);
lblTitle.numberOfLines=3;
self.navigationItem.titleView = lblTitle;

swift

let label = UILabel(frame: CGRect(x:0, y:0, width:150, height:50))
    label.backgroundColor = UIColor.clear
    label.numberOfLines = 3
    label.font = UIFont.boldSystemFont(ofSize: 16.0)
    label.textColor = UIColor.blackColor
    label.text = "This is a multiline string for the navBar details"
    self.navigationItem.titleView = label
Harshal Shah
  • 427
  • 3
  • 5
  • This was pointed out by @Dopapp and as I mentioned, I have already tried this. This only confines the label within the fixed bounds of navigationItem's titleView. – unspokenblabber Jun 27 '17 at 17:15