, , , , .
-, ( - UITabBarController, ) - .
(, OP, TabbarController Nav Controller, ).
, , , UIViewController , .
UIViewController Tab - UILabel . > .
UIViewController :
extension UIViewController {
func addNavItemTitle(resourceString: String, textColor: UIColor = UIColor.white) {
let titleLabel = UILabel()
titleLabel.text = NSLocalizedString(resourceString)
titleLabel.textColor = textColor
titleLabel.font = UIFont.viewTitle
titleLabel.sizeToFit()
self.navigationItem.titleView = titleLabel
}
}
, . , .
.
, , , Tab, addNavItemTitle(resourceString: "example.title")
viewDidLoad
You may also have noticed that my call is NSLocalizedStringmissing an argument. This is because I tend to use the same line for comment as the resource line. So I created a global function to simplify the call without repeating the line.
Same:
public func NSLocalizedString(_ key: String) -> String {
return NSLocalizedString(key, comment: key)
}
source
share