代码之家  ›  专栏  ›  技术社区  ›  Ahmed Adnan Qazzaz

UIDocumentPicker导航栏按钮隐藏在iOS 11中

  •  7
  • Ahmed Adnan Qazzaz  · 技术社区  · 7 年前

    我注意到我的UIDocumentPicker的导航栏中有一个问题,仅在iOS 11上,完成、取消或编辑按钮不可见,当用户触摸它时,它就会出现,即正常状态下的颜色是白色,即使在更改 UINavigationBar.appearnce().tintColor ,颜色仅在触摸时改变。

    enter image description here enter image description here

    3 回复  |  直到 7 年前
        1
  •  4
  •   Ahmed Adnan Qazzaz    7 年前

    不知为什么,我发现如果使用 Objective-C 并设置 [UINavigationBar appearance].tintColor = [UIColor black]; 在里面 viewWillAppear func,并在 viewWillDisappear ,效果很好。

    但是如果你用同样的方法 swift 它不会。

        2
  •  4
  •   Antoine Lamy    7 年前

    我不太喜欢把全球形象设定在 viewWillAppear viewWillDisappear . 外观API只能在应用程序启动时使用。您只需重置 UIDocumentPickerViewController 只有通过将此代码放入 application:didFinishLaunchingWithOptions: 条形按钮将返回其原始蓝色:

    if #available(iOS 11.0, *) {
        UINavigationBar.appearance(whenContainedInInstancesOf: [UIDocumentBrowserViewController.self]).tintColor = nil
    }
    
        3
  •  3
  •   Sajidh Zahir    6 年前

    将CustomDocumentPickerViewController与黑色一起使用 appearance 对于 UINavigationBar UIBarButtonItem

    import UIKit
    
    class CustomDocumentPickerViewController: UIDocumentPickerViewController {
    
        override func viewWillAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
    
            UINavigationBar.appearance().tintColor = UIColor.black
            UIBarButtonItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.black], for: .normal)
        }
    
        override func viewWillDisappear(_ animated: Bool) {
    
            UINavigationBar.appearance().tintColor = UIColor.white // your color
            UIBarButtonItem.appearance().setTitleTextAttributes(nil, for: .normal)
            super.viewWillDisappear(animated)
    
        }
    
    }