在UIActivityViewController中改变UIBarButtonItems的色调

时间:2022-09-17 21:39:00

I have a navigation bar that uses white tint color on a dark background color. I use UIActivityViewController to share a link with the iOS share sheet.

我有一个导航条,在黑色的背景色上使用白色的色调。我使用UIActivityViewController与iOS共享表共享一个链接。

When I select WhatsApp or Messages app to share the content the navigation buttons have the default blue tint color. Also the searchbar (in the case of WhatsApp) has a gray tint color which really makes it hard to read.

当我选择WhatsApp或message app来共享内容时,导航按钮的颜色默认为蓝色。此外,searchbar(以WhatsApp为例)有一种灰色的色调,真的让人很难阅读。

I couldn't manage to change the tint color. My code:

我无法改变颜色。我的代码:

let textToShare = "Visit my website!"
if let myWebsite = NSURL(string: "http://google.com") {
    let objectsToShare = [textToShare, myWebsite]
    let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

    self.presentViewController(activityVC, animated: true, completion: {
        activityVC.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
        activityVC.navigationController?.navigationItem.rightBarButtonItem?.tintColor = UIColor.whiteColor()   
        activityVC.navigationController?.navigationItem.leftBarButtonItem?.tintColor = UIColor.whiteColor()
    })
}

Any ideas?

什么好主意吗?

Edit:

编辑:

This is not a duplicate question because it is not about the button tint color of the activity view controller. It is about the button color of the navigation controller of the view controller that is shown after e.g. share on iMessage is pressed.

这不是一个重复的问题,因为它与活动视图控制器的按钮色调无关。它是关于视图控制器的导航控制器的按钮颜色,例如按下iMessage上的share。

1 个解决方案

#1


1  

You can set the tintColor for view controllers presented by UIActivityViewController by setting the tintColor on your app delegate's UIWindow instance. Setting tintColor on UIActivityViewController seems to have no effect regardless of when or how you set it.

你可以为UIActivityViewController提供的视图控制器设置tintColor,方法是在你的app委托的UIWindow实例上设置tintColor。在UIActivityViewController中设置tintColor似乎没有效果,无论何时或如何设置它。

In your app delegate:

在你的应用程序委托:

    self.window.tintColor = [theme navBarItemsTintColor];

#1


1  

You can set the tintColor for view controllers presented by UIActivityViewController by setting the tintColor on your app delegate's UIWindow instance. Setting tintColor on UIActivityViewController seems to have no effect regardless of when or how you set it.

你可以为UIActivityViewController提供的视图控制器设置tintColor,方法是在你的app委托的UIWindow实例上设置tintColor。在UIActivityViewController中设置tintColor似乎没有效果,无论何时或如何设置它。

In your app delegate:

在你的应用程序委托:

    self.window.tintColor = [theme navBarItemsTintColor];