iOS7 - Change UINavigationBar border color

后端 未结 15 2083
时光取名叫无心
时光取名叫无心 2020-12-07 14:44

Is it possible to change the grey border-bottom color of the UINavigationBar in iOS7?

I already tried to remove to border, but this is not working:

[         


        
15条回答
  •  孤街浪徒
    2020-12-07 15:16

    I wrote an extension based on the other answers for easier usage in Swift:

    extension UINavigationBar {
    
        func setBottomBorderColor(color: UIColor) {
    
            let navigationSeparator = UIView(frame: CGRectMake(0, self.frame.size.height - 0.5, self.frame.size.width, 0.5))
            navigationSeparator.backgroundColor = color
            navigationSeparator.opaque = true
            navigationSeparator.tag = 123
            if let oldView = self.viewWithTag(123) {
                oldView.removeFromSuperview()
            }
            self.addSubview(navigationSeparator)
    
        }
    }
    

    You can use this extension with calling the method in a context like that:

    self.navigationController?.navigationBar.setBottomBorderColor(UIColor.whiteColor())
    

    I found that pretty useful as I had to deal with that colored-border-problem.

提交回复
热议问题