Swift Solution:
2 lines in the NavigationBar :
private func setupTitleView() { let topText = NSLocalizedString("key", comment: "") let bottomText = NSLocalizedString("key", comment: "") let titleParameters = [NSForegroundColorAttributeName : UIColor.<Color>(), NSFontAttributeName : UIFont.<Font>] let subtitleParameters = [NSForegroundColorAttributeName : UIColor.<Color>(), NSFontAttributeName : UIFont.<Font>] let title:NSMutableAttributedString = NSMutableAttributedString(string: topText, attributes: titleParameters) let subtitle:NSAttributedString = NSAttributedString(string: bottomText, attributes: subtitleParameters) title.appendAttributedString(NSAttributedString(string: "\n")) title.appendAttributedString(subtitle) let size = title.size() let width = size.width guard let height = navigationController?.navigationBar.frame.size.height else {return} let titleLabel = UILabel(frame: CGRectMake(0,0, width, height)) titleLabel.attributedText = title titleLabel.numberOfLines = 0 titleLabel.textAlignment = .Center navigationItem.titleView = titleLabel }
2 row in BarButton
let string = NSLocalizedString("key", comment: "") let attributes = [NSForegroundColorAttributeName : UIColor.<Color>, NSFontAttributeName : UIFont.<Font>] let size = (string as NSString).sizeWithAttributes(attributes) guard let height = navigationController?.navigationBar.frame.size.height else {return} let button:UIButton = UIButton(frame: CGRectMake(0, 0, size.width, height)) button.setAttributedTitle(NSAttributedString(string: string, attributes: attributes), forState: .Normal) button.addTarget(self, action: #selector(<SELECTOR>), forControlEvents: .TouchUpInside) button.titleLabel?.numberOfLines = 0 button.titleLabel?.textAlignment = .Right let rightBarButton = UIBarButtonItem(customView: button) navigationItem.rightBarButtonItem = rightBarButton
the result is

gbk Oct 10 '16 at 11:32 2016-10-10 11:32
source share