首页 文章

UIActivityViewController更改导航栏文本颜色

提问于
浏览
5

我正在创建一个UIActivityViewController并尝试在点击共享消息图标后更改其文本颜色 .

默认情况下,我在_1545663中将导航栏文本颜色设置为白色,就像这样

UINavigationBar.appearance().tintColor = whiteColor
UIBarButtonItem.appearance().tintColor = whiteColor

但是对于UIActivityViewController,我想让它成为默认值(即黑色 Headers 文本和蓝色 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)

白色文本的结果仍然相同:

如果仔细查看图像,导航栏的 Headers 和右侧栏按钮项目中都有白色文本 .

enter image description here

2 回答

  • 3

    在iOS 11中,您可以通过设置更改“通过消息屏幕共享”中的取消按钮颜色:

    UIButton.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor = .blue
    
  • 0

    如果您在app delegate类中自定义导航栏,则应在共享操作(按下共享按钮等)之前更改它,但不要忘记在共享操作完成或解除时将其更改回来,因此您需要自定义在您共享操作的类的viewWillAppear func处的导航栏 .

    它应该是这样的:

    class ShareActionViewController: UIViewController {
    
        override func viewWillAppear(_ animated: Bool) {
            super.viewWillAppear(animated)
            //this should be same with your appDel settings:
            UINavigationBar.appearance().tintColor = .white
            UINavigationBar.appearance().barTintColor = .appPurpleColor
        }
    
        fileprivate func shareButtonPressed() {
            UINavigationBar.appearance().tintColor = .purple
            UINavigationBar.appearance().barTintColor = .white 
        }
    
    }
    

相关问题