sim*_*ons 5 ios swift uidocumentpickervc
我在 Xcode 7.0 beta 6 中使用 Swift 2
长话短说,我正在尝试解决如何设置 .navigationBar.barStyle以及navigationBar.tintColor何时使用文档选择器访问 iCloud——即UIDocumentPickerViewController.
我试过例如:
/...
documentPicker.navigationController!.navigationBar.barStyle = UIBarStyle.Default
documentPicker.navigationController!.navigationBar.tintColor = UIColor.orangeColor()
/...
Run Code Online (Sandbox Code Playgroud)
例如。在这里,我在导航控制器中嵌入了一个视图控制器:
在MyNavigationController我可以设置.barStyle和.tintStyle如下:
class MyNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationBar.barStyle = UIBarStyle.Default
self.navigationBar.tintColor = UIColor.orangeColor()
}
}
Run Code Online (Sandbox Code Playgroud)
因此,.tintStyle为橙色如下:
iCloud 已启用并FirstViewController符合UIDocumentPickerDelegate. 条形按钮调用IBAction如下代码所示的函数FirstViewController:
class FirstViewController: UIViewController, UIDocumentPickerDelegate {
// ...
@IBAction func importDocument(sender: UIBarButtonItem) {
let documentPicker: UIDocumentPickerViewController = UIDocumentPickerViewController(documentTypes: ["public.text"], inMode: UIDocumentPickerMode.Import)
documentPicker.delegate = self
documentPicker.modalPresentationStyle = UIModalPresentationStyle.FullScreen
documentPicker.popoverPresentationController?.barButtonItem = sender
self.presentViewController(documentPicker, animated: true, completion: nil)
}
func documentPicker(controller: UIDocumentPickerViewController, didPickDocumentAtURL url: NSURL) {
// ...
}
func documentPickerWasCancelled(controller: UIDocumentPickerViewController) {
// ...
}
}
Run Code Online (Sandbox Code Playgroud)
那个有效。文档选择器按预期加载:
但。为了弄清楚如何做到这一点,我希望菜单项“完成”为橙色。像以前一样。
我尝试将以下代码添加到@IBAction如下:
//...
documentPicker.navigationController!.navigationBar.barStyle = UIBarStyle.Default
documentPicker.navigationController!.navigationBar.tintColor = UIColor.orangeColor()
self.presentViewController(documentPicker, animated: true, completion: nil)
//...
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为此时documentPicker.navigationController是nil.
谁能告诉我我可以如何访问或访问循环中的哪个位置documentPicker.navigationController!.navigationBar.tintColor?
或者也许我遗漏了一些东西,还有其他一些改变菜单颜色的方法?
或者也许我应该寻找创建一个自定义导航控制器 - 和一个自定义文档选择器视图控制器。然后理论上我将能够访问相关的viewDidLoad. 我试过了,但意识到我还需要一个自定义版本的UIDocumentPickerDelegate协议。肯定有一个更简单的解决方案(我怀疑是否允许这样做)。
您可以通过以下方式更改导航栏默认色调颜色UIAppearance:
UINavigationBar.appearance().tintColor = UIColor.orangeColor()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3281 次 |
| 最近记录: |