我想在某个viewcontroller中设置白色barTintColor
我设置了$table = Tablename::get();
foreach ($table as $value){
echo $value->22 // Getting column 22 from table
}
对于所有默认颜色,但当我使用外观whenContainedInInstancesOf
它没有改变我的viewcontroller
UINavigationBar.appearance().barTintColor
有什么想法吗?我在我的viewcontroller中试过这个
UINavigationBar.appearance(whenContainedInInstancesOf: [MyViewController.self]).barTintColor = .white
但是当屏幕消失时我必须将颜色设置回默认值。我不想这样做。我该怎么办?
答案 0 :(得分:4)
UINavigationBar
包含在UINavigationController
而非UIViewController
表示您需要创建自定义UINavigationController
空班级将完成这项工作
class NavigationController: UINavigationController {}
然后我们可以使用它
UINavigationBar.appearance(whenContainedInInstancesOf: [NavigationController.self]).barTintColor = .white
可以找到示例here
答案 1 :(得分:4)
@zombie有正确的答案。我刚刚用UISearchBar遇到过这个问题。这是答案的Swift 3版本。在此示例中,使用.red
作为示例UIColor
。
let textField = UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self])
textField.tintColor = .red
let searchBar = UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self])
searchBar.setTitleTextAttributes([NSForegroundColorAttributeName: .red], for: .normal)
searchBar.setTitleTextAttributes([NSForegroundColorAttributeName: .red], for: .disabled)
答案 2 :(得分:1)
// For the cursor color
let textField = UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self])
textField.tintColor = .lightBlue
// For the cancel button on search bar
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.white], for: .normal)
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes([NSAttributedStringKey.foregroundColor: UIColor.lightText], for: .disabled)
答案 3 :(得分:0)
UIBarButtonItem.appearance(whenContainedInInstancesOf: [UIImagePickerController.self]).setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.black], for: .normal)
这对我有用!