【问题标题】:How to change UIDocumentInteractionController Done button text and background color如何更改 UIDocumentInteractionController 完成按钮文本和背景颜色
【发布时间】:2017-07-21 19:14:26
【问题描述】:

如何更改完成按钮的背景颜色和文本颜色?有没有办法可以更改导航栏颜色和导航栏标题颜色和底栏颜色?附上截图供参考:

【问题讨论】:

  • 截图在哪里
  • 我可以看到随附的屏幕截图。你看不到吗?需要重新上传吗?
  • 我现在可以看到了,刚才它说'imgur is over capacity'
  • @Dee:你解决了吗?我也有同样的问题。我设置了 BarTintColor,但是好像没有效果。

标签: ios iphone swift uinavigationcontroller uidocumentinteraction


【解决方案1】:

我解决了。这是对我来说完美的代码:

func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
    UINavigationBar.appearance().barTintColor = Colors.redColor()
    UINavigationBar.appearance().tintColor = UIColor.white
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white, NSFontAttributeName: UIFont.systemFont(ofSize: 14, weight: UIFontWeightBold)]
    return self
}

【讨论】:

  • 工作正常,但不要忘记恢复到以前的状态!我在呈现预览的视图中的“viewWillAppear”中执行此操作。
  • 我在 AppDelegate.swift 中有很多自定义。要在预览窗口(和所有子视图)中获得正确的颜色,我必须在 AppDelegate 中删除它: window?.tintColor = x 并将其添加到上面的列表中: UILabel.appearance().textColor = CommonColors.appleTint UIButton.appearance( ).tintColor = CommonColors.appleTint
【解决方案2】:

我有一个想法来改变条形颜色:

let allNavigationBar = UINavigationBar.appearance()
allNavigationBar.barTintColor = UIColor.red  // change the bar background color
allNavigationBar.tintColor = UIColor.black // change the Done button's tintColor

let alloolbar = UIToolbar.appearance()
allToolbar.barTintColor = UIColor.red  // dones't work, try backgroundImage
allToolbar.backgroundColor = UIColor.blue // dones't work
allToolbar.tintColor = UIColor.brown // change the toolbar's item tint color

但是这个方法效果很好,你所有的UINavigationBarUIToolBar都会做出改变。

希望其他人可以提供更好的解决方案。

【讨论】:

    【解决方案3】:

    这有点笨拙,因为它依赖于 QLPreviewController 是实现 UIDocumentInteractionController 的类这一事实,但这样的事情是侵入性最小的解决方案。在显示 UIDocumentInteractionController 之前执行此操作

    import QuickLook
    
    UIBarButtonItem.appearance(whenContainedInInstancesOf [QLPreviewController.self]).tintColor = UIColor.black
    

    【讨论】:

    • 对于 Swift 4: UIBarButtonItem.appearance(whenContainedInInstancesOf: [QLPreviewController.self]).tintColor = UIColor.black 它适用于预览,但如何在共享时更改“OpenInMenu”页脚的色调颜色文件(在预览视图中按共享按钮)?与 docController.presentOpenInMenu 相同。
    【解决方案4】:

    您可以临时更改窗口的色调。

    func presentDocument() {
        //present the controller here
        self.appDelegate.window.tintColor = UIColor.red
    }
    

    然后再改回来:

    func documentInteractionControllerDidEndPreview(documentInteractionController) { //replace parameter with your uidocumentviewinteractioncontroller
        self.appDelegate.window.tintColor = UIColor.white
    }
    

    【讨论】:

      【解决方案5】:

      @迪。我猜你已经在你的另一个问题中问过这部分。在这种情况下,您无法显示该预览控制器。在那个问题中,建议的答案是从该委托方法返回“自我”。如果您正确实施,那么您的预览将使用与其父控制器使用的相同导航栏颜色。我的意思是,如果您直接从某个 ViewController 打开 UIDocumentInteractionController,那么 UIDocumentInteractionController 将使用其父 viewController 的导航栏颜色。这可能会帮助您更改完成按钮的颜色

      【讨论】:

      • 我现在可以修改导航栏按钮的标题和文本以及背景颜色。但底部工具栏颜色不起作用。你能帮我解决这个问题吗
      • @Dee 我无法修改导航栏按钮的标题和文本以及背景颜色。你是怎么做到的?
      【解决方案6】:

      试试这个:(你需要实现 UIDocumentInteractionControllerDelegate)

      func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
          return self.navigationController ?? self
      }
      

      【讨论】:

        【解决方案7】:
             let QLNavAppearance = UINavigationBar.appearance(whenContainedInInstancesOf: [QLPreviewController.self])
            QLNavAppearance.tintColor = UIColor.red // some
            QLNavAppearance.barTintColor =  UIColor.red // some
            QLNavAppearance.backgroundColor =  UIColor.red // some
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2020-11-07
          • 2013-10-24
          • 2017-08-31
          • 2015-06-04
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多