iOS Swift3.x 設(shè)置導(dǎo)航欄 分欄控制器 狀態(tài)欄
測試 (Swift3.x + Xcode 8.1 + iPhone 7p 模擬器)
分欄控制器(UITabbar)
// 設(shè)置字體顏色
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.black,
NSFontAttributeName: UIFont.systemFont(ofSize: 10, weight: 1.5)], for: .selected)
// 設(shè)置分欄控制器為透明/隱藏黑色線條
self.tabBar.backgroundImage = UIImage()
self.tabBar.shadowImage = UIImage()
導(dǎo)航欄控制器(UINavgationBar)
// 設(shè)置導(dǎo)航欄為透明的白色
self.navigationController?.navigationBar.barTintColor = UIColor.black
self.navigationController?.navigationBar.hideBottomHairLine()
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont.systemFont(ofSize: 16),
NSForegroundColorAttributeName: UIColor.white]
// MARK: - 擴(kuò)展 UINavigationBar 顯示/隱藏 黑色線條
extension UINavigationBar {
func hideBottomHairLine() {
let navigationBarImageView = hairLineImageViewInNavigationBar(view: self)
navigationBarImageView?.isHidden = true
}
func showBottomHairLine() {
let navigationBarImageView = hairLineImageViewInNavigationBar(view: self)
navigationBarImageView?.isHidden = false
}
func hairLineImageViewInNavigationBar(view: UIView) -> UIImageView? {
if view.isKind(of: UIImageView.self) && view.bounds.height <= 1.0 {
return (view as! UIImageView)
}
let subViews = (view.subviews as [UIView])
for subView: UIView in subViews {
if let imageView: UIImageView = hairLineImageViewInNavigationBar(view: subView) {
return imageView
}
}
return nil
}
}
狀態(tài)欄設(shè)置為白色的字(UIStatusBarStyle)
Info.plist 加上 View controller-based status bar appearance 設(shè)置 NO
點(diǎn)擊項(xiàng)目 General -> Deployment Info -> Status Bary Style -> Light