iOS 开发随笔iOS开发知识小集iOS Developer

UINavigationBar基础的使用总结

2017-08-18  本文已影响601人  sun5kong
FrQi3.png
        let nav = UINavigationBar.appearance()
        
        let shadow = NSShadow()
        shadow.shadowOffset = CGSize(width: 0, height: 0)
        let attributes = [NSForegroundColorAttributeName: UIColor.white,
                          NSFontAttributeName: UIFont.systemFont(ofSize: 16),
                          NSShadowAttributeName: shadow]
        nav.titleTextAttributes = attributes
 self.navigationController?.navigationBar.barTintColor = UIColor.red
屏幕快照 2017-08-18 上午10.35.00.png
self.navigationController?.navigationBar.setBackgroundImage(UIImage(named: "personalBackgroundImage"), for: .default)
屏幕快照 2017-08-18 上午10.44.26.png
extension UINavigationBar {
    func hideBottomHairline() {
        self.hairlineImageView?.isHidden = true
    }
    func showBottomHairline() {
        self.hairlineImageView?.isHidden = false
    }
}
extension UIView {
    fileprivate var hairlineImageView: UIImageView? {
        return hairlineImageView(in: self)
    }
    fileprivate func hairlineImageView(in view: UIView) -> UIImageView? {
        if let imageView = view as? UIImageView, imageView.bounds.height <= 1.0 {
            return imageView
        }
        
        for subview in view.subviews {
            if let imageView = self.hairlineImageView(in: subview) { return imageView }
        }
        
        return nil
    }
}
上一篇下一篇

猜你喜欢

热点阅读