Цвет панели навигации установлен неправильно - PullRequest
0 голосов
/ 20 мая 2019

Я пытаюсь установить цвет панели навигации.Я не использую раскадровки в этом приложении, поэтому это должно быть сделано в коде.В настоящее время у меня есть это:

 navigationController.navigationBar.isHidden = false
 navigationController.navigationBar.backgroundColor = UIColor(named: "tint")

 navigationController.navigationBar.shadowImage = UIImage()
 navigationController.navigationBar.isTranslucent = true
 navigationController.navigationBar.setBackgroundImage(UIImage(), for: .default)
 navigationController.navigationBar.tintColor = .white
 navigationController.navigationBar.titleTextAttributes  =[NSAttributedString.Key.foregroundColor: UIColor.white] 

В действительности я получил: enter image description here

Почему цвет над панелью навигации не совпадает?

Ответы [ 2 ]

0 голосов
/ 20 мая 2019
UINavigationBar.appearance().backgroundColor = UIColor.greenColor()
UIBarButtonItem.appearance().tintColor = UIColor.magentaColor()
UINavigationBar.appearance().titleTextAttributes = [UITextAttributeTextColor: UIColor.blueColor()]
UITabBar.appearance().backgroundColor = UIColor.yellowColor();

Подробнее о UIAppearance API в Swift вы можете прочитать здесь: https://developer.apple.com/documentation/uikit/uiappearance

ИЛИ

UINavigationBar.appearance().barTintColor = .black
UINavigationBar.appearance().tintColor = .white
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
UINavigationBar.appearance().isTranslucent = false
0 голосов
/ 20 мая 2019

Попробуйте приведенный ниже код с вашим цветным кодом RGB

let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)
let statusBarColor = UIColor(red: 74/255, green: 171/255, blue: 247/255, alpha: 1.0)
statusBarView.backgroundColor = statusBarColor
view.addSubview(statusBarView)

Просто введите этот код в viewDidLoad()

Надеюсь, что это работает !!

...