简体   繁体   English

无法更改共享扩展名导航栏标题颜色(快速)

[英]Can't change share extension navigation bar title color (Swift)

I am trying to change the navigation bars title color using the below code but it won't change. 我正在尝试使用以下代码更改导航栏标题的颜色,但不会更改。 The tint and background color work perfectly. 色彩和背景色完美搭配。

 let nav = navigationController?.navigationBar

 nav?.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
 nav?.tintColor = UIColor.white
 nav?.backgroundColor = UIColor.green.primary
 title = "Share"

I haven't changed anything in the App Delegate. 我没有更改应用程序委托中的任何内容。

Info.plist 信息清单

<key>NSExtension</key>
    <dict>
        <key>NSExtensionAttributes</key>
        <dict>
            <key>NSExtensionActivationRule</key>
            <dict>
                <key>NSExtensionActivationSupportsText</key>
                <string>1</string>
            </dict>
            <key>NSExtensionJavaScriptPreprocessingFile</key>
            <string>Action</string>
        </dict>
        <key>NSExtensionMainStoryboard</key>
        <string>MainInterface</string>
        <key>NSExtensionPointIdentifier</key>
        <string>com.apple.share-services</string>
    </dict>

Try change appearance of navigation 尝试更改导航的外观

UINavigationBar.appearance().tintColor = .black

I made a share extension recently, but just change navigationBar's color doesn't work too. 我最近做了一个共享扩展程序,但只是更改navigationBar的颜色也不起作用。

Try this solution: 试试这个解决方案:

self.navigationController?.navigationBar.barTintColor = UIColor.black
self.navigationController?.navigationBar.tintColor = UIColor.black
let titleDict = [NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.font:constantsNaming.fontType.kOpenSans_SemiBoldLarge!]
self.navigationController?.navigationBar.titleTextAttributes = titleDict

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM