Last active
August 21, 2019 13:49
-
-
Save matt-curtis/c0fa7aa820d6257e7b2a to your computer and use it in GitHub Desktop.
UINavigationBar Multiline Title
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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