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

839 Views Asked by At

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>
2

There are 2 best solutions below

0
On

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.

0
On

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