Skip to content

Instantly share code, notes, and snippets.

@matt-curtis
Last active August 21, 2019 13:49
Show Gist options
  • Save matt-curtis/c0fa7aa820d6257e7b2a to your computer and use it in GitHub Desktop.
Save matt-curtis/c0fa7aa820d6257e7b2a to your computer and use it in GitHub Desktop.
UINavigationBar Multiline Title
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
if(!self.navigationItem.titleView){
self.navigationItem.titleView = ({
UILabel *titleView = [UILabel new];
titleView.numberOfLines = 0;
titleView.textAlignment = NSTextAlignmentCenter;
titleView.attributedText = [[NSAttributedString alloc] initWithString:@"2\nLINES" attributes:
self.navigationController.navigationBar.titleTextAttributes
];
[titleView sizeToFit];
// You'll need to set your frame otherwise if your line breaks aren't explcit.
titleView;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment