, , LargeTitle:
1
:
(Main.storyboard).
.
""> ""> " ".
2
:
" "> ""> " ".
" " .
3
:
func setTitle(title:String, subtitle:String) -> UIView {
let navigationBarHeight = Int(self.navigationController!.navigationBar.frame.height)
let navigationBarWidth = Int(self.navigationController!.navigationBar.frame.width)
var y_Title = 0.0
var y_SubTitle = 0.0
if UIDevice().userInterfaceIdiom == .phone {
switch UIScreen.main.nativeBounds.height {
case 1136:
y_Title = 46
y_SubTitle = 36
print("iPhone 5S and SE")
case 1334, 1920, 2208, 2436:
y_Title = 48
y_SubTitle = 38
print("iPhone 6, 6+, 6S, 6S+, 7, 7+, 8, 8+ and X")
default:
y_Title = 46
y_SubTitle = 36
print("Default")
}
}
let titleFont = UIFont.systemFont(ofSize: 33, weight: UIFont.Weight.bold)
let subTitleFont = UIFont.systemFont(ofSize: 12, weight: UIFont.Weight.semibold)
let titleLabel = UILabel(frame: CGRect(x: 8.5, y: y_Title, width: 0, height: 0))
titleLabel.backgroundColor = UIColor.clear
titleLabel.textColor = UIColor.black
titleLabel.font = titleFont
titleLabel.text = title
titleLabel.sizeToFit()
let subtitleLabel = UILabel(frame: CGRect(x: 8.5, y: y_SubTitle, width: 0, height: 0))
subtitleLabel.backgroundColor = UIColor.clear
subtitleLabel.textColor = UIColor.gray
subtitleLabel.font = subTitleFont
subtitleLabel.text = subtitle
subtitleLabel.sizeToFit()
let titleView = UIView(frame: CGRect(x: 0, y: 0, width: navigationBarWidth, height: navigationBarHeight))
titleView.addSubview(titleLabel)
titleView.addSubview(subtitleLabel)
return titleView
}
viewDidLoad():
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.titleView = setTitle(title: "Title", subtitle: "SUBTITLE")
}