Change navigation bar bottom border color Swift

前端 未结 8 1277
时光取名叫无心
时光取名叫无心 2020-12-30 21:36

It works with

import UIKit

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup a         


        
8条回答
  •  萌比男神i
    2020-12-30 22:40

    From iOS 13 on, you can use the UINavigationBarAppearance() class with the shadowColor property:

    if #available(iOS 13.0, *) {
      let style = UINavigationBarAppearance()
      style.shadowColor = UIColor.clear // Effectively removes the border
      navigationController?.navigationBar.standardAppearance = style
    
      // Optional info for follow-ups:
      // The above will override other navigation bar properties so you may have to assign them here, for example:
      //style.buttonAppearance.normal.titleTextAttributes = [.font: UIFont(name: "YourFontName", size: 17)!]
      //style.backgroundColor = UIColor.orange
      //style.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white,
                                   NSAttributedString.Key.font: UIFont(name: "AnotherFontName", size: 20.0)!]
    } else {
      // Fallback on earlier versions
    }
    

提交回复
热议问题