如何在UIActivityViewController上按下取消按钮时更改NavigationController文本颜色?

时间:2023-02-02 20:31:07

The color text is white for NavigationController text but changing it to white when a user presses the share button (to show cancel button). But when user press cancel button and returns from text composing then the color remains same and not change back to white.

对于NavigationController文本,颜色文本为白色,但在用户按下共享按钮时将其更改为白色(以显示取消按钮)。但是当用户按下取消按钮并从文本编写返回时,颜色保持不变,不会变回白色。

The completion handler is detected as I see the print in the log but it doesn't change the color.

检查完成处理程序,因为我在日志中看到打印但它不会改变颜色。

func completionHandler(activityType: UIActivityType?, shared: Bool, items: [Any]?, error: Error?) {
    if (shared) {
        print("Cool user shared some stuff")
    }
    else {
        print("Bad user canceled sharing :(")
        UIButton.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor = .white
        navigationController?.navigationBar.largeTitleTextAttributes = [
            NSAttributedStringKey.foregroundColor : UIColor.white
        ]
        navigationController?.navigationBar.titleTextAttributes = [
            NSAttributedStringKey.foregroundColor : UIColor.white
        ]

    }

}

1 个解决方案

#1


0  

Removed completion handler and all the code related to changing color for tint color and only added the following to search bar.

删除了完成处理程序以及与更改颜色的颜色相关的所有代码,并且仅将以下内容添加到搜索栏。

UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).tintColor = .white

If I click on Search Bar now the cancel button color is white and when I share content through Message the composing text "cancel" button color is the default (blue).

如果我现在点击搜索栏,取消按钮颜色为白色,当我通过消息共享内容时,撰写文本“取消”按钮颜色是默认颜色(蓝色)。

#1


0  

Removed completion handler and all the code related to changing color for tint color and only added the following to search bar.

删除了完成处理程序以及与更改颜色的颜色相关的所有代码,并且仅将以下内容添加到搜索栏。

UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).tintColor = .white

If I click on Search Bar now the cancel button color is white and when I share content through Message the composing text "cancel" button color is the default (blue).

如果我现在点击搜索栏,取消按钮颜色为白色,当我通过消息共享内容时,撰写文本“取消”按钮颜色是默认颜色(蓝色)。