Sim*_*mon 6 ios uiactivityviewcontroller swift
我正在创建一个UIActivityViewController并尝试在点击共享消息图标后更改其文本颜色.
默认情况下,我将导航栏文本颜色设置为白色AppDelegate等
UINavigationBar.appearance().tintColor = whiteColor
UIBarButtonItem.appearance().tintColor = whiteColor
Run Code Online (Sandbox Code Playgroud)
但是对于UIActivityViewController,我想把它作为默认值(即黑色标题文本和蓝色Cancel按钮)
我试过以下没有运气:
let shareText = "text to share"
let activityViewController = UIActivityViewController(activityItems: [shareText], applicationActivities: [])
activityViewController.navigationController?.navigationBar.tintColor = UIColor.black
activityViewController.navigationController?.navigationItem.rightBarButtonItem?.tintColor = UIColor.blue
present(activityViewController, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
白色文本的结果仍然相同:
如果仔细查看图像,导航栏的标题和右侧栏按钮项目中都有白色文本.
对于试图做类似事情的其他人。UIActivityViewController 在完成时给我们一个回调。我们可以做的是,更改 UIBarButtonItem 颜色,然后在完成后将其设置回我们的原始颜色。
对我来说,完成处理程序没有正确地将颜色设置回原始颜色,所以我必须在 viewWillAppear 中进行。
// Setting the required color for the bar buttons on share activities
UIBarButtonItem.appearance().setTitleTextAttributes([.foregroundColor: UIColor.yourRequiredColor], for: .normal)
// Re-setting the default color for the bar buttons again on activity's completion
activityViewController.completionWithItemsHandler = { (activityType, completed:Bool, returnedItems:[Any]?, error: Error?) in
UIBarButtonItem.appearance().setTitleTextAttributes([.foregroundColor: UIColor.yourOriginalColor], for: .normal)
}
Run Code Online (Sandbox Code Playgroud)
小智 4
在 iOS 11 中,您可以通过设置更改“通过消息屏幕共享”中的取消按钮颜色:
UIButton.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor = .blue
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1766 次 |
| 最近记录: |