iOS Swift3.x 设置导航栏 分栏控制器 状态栏
测试 (Swift3.x + Xcode 8.1 + iPhone 7p 模拟器)
分栏控制器(UITabbar)
// 设置字体颜色
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.black,
NSFontAttributeName: UIFont.systemFont(ofSize: 10, weight: 1.5)], for: .selected)
// 设置分栏控制器为透明/隐藏黑色线条
self.tabBar.backgroundImage = UIImage()
self.tabBar.shadowImage = UIImage()
导航栏控制器(UINavgationBar)
// 设置导航栏为透明的白色
self.navigationController?.navigationBar.barTintColor = UIColor.black
self.navigationController?.navigationBar.hideBottomHairLine()
self.navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont.systemFont(ofSize: 16),
NSForegroundColorAttributeName: UIColor.white]
// MARK: - 扩展 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
}
}
状态栏设置为白色的字(UIStatusBarStyle)
Info.plist 加上 View controller-based status bar appearance 设置 NO
点击项目 General -> Deployment Info -> Status Bary Style -> Light
Simulator Screen Shot 2016年12月20日 16.05.58.png