[文章]如何隐藏UINavigationbar下面的黑线,swift版

先建一个UIBarExtension.swift的文件来扩展UINavigationBar

import Foundation
import UIKit

extension UINavigationBar {

    func hideBottomHairline() {
        let navigationBarImageView = hairlineImageViewInNavigationBar(self)
        navigationBarImageView!.hidden = true
    }

    func showBottomHairline() {
        let navigationBarImageView = hairlineImageViewInNavigationBar(self)
        navigationBarImageView!.hidden = false
    }

    private func hairlineImageViewInNavigationBar(view: UIView) -> UIImageView? {
        if view.isKindOfClass(UIImageView) && 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(subview)? {
                return imageView
            }
        }

        return nil
    }

}

extension UIToolbar {

    func hideHairline() {
        let navigationBarImageView = hairlineImageViewInToolbar(self)
        navigationBarImageView!.hidden = true
    }

    func showHairline() {
        let navigationBarImageView = hairlineImageViewInToolbar(self)
        navigationBarImageView!.hidden = false
    }

    private func hairlineImageViewInToolbar(view: UIView) -> UIImageView? {
        if view.isKindOfClass(UIImageView) && view.bounds.height <= 1.0 {
            return (view as UIImageView)
        }

        let subviews = (view.subviews as [UIView])
        for subview: UIView in subviews {
            if let imageView: UIImageView = hairlineImageViewInToolbar(subview)? {
                return imageView
            }
        }

        return nil
    }

}

再在viewDidLoad里使用

let navigationBar = self.navigationController?.navigationBar
navigationBar?.hideBottomHairline()

[绘画]圣斗士星矢,冰河和舜

[绘画]一些练习

 

[绘画]最近的练习,包括对大师作品的临摹和烈火后的龙女觉醒

[绘画]最近画的一些权利游戏的角色