CuriousDev
CuriousDev

Reputation: 311

How to change navigation bar and barbuttonitem color & font on Modal view of activity in UIActivityViewController?

I have set the status bar to light content by setting view-controller based status bar in Info.plist to No as i am using dark color for navigation bar. I was able to set navigation bar color and bar button item color and font using following code in AppDelegate.swift -

UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent
    UINavigationBar.appearance().barTintColor = UIColor.darkGrayColor()
    UINavigationBar.appearance().translucent = false


    if #available(iOS 8.2, *) {
        UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName : UIFont.systemFontOfSize(16.0, weight: UIFontWeightThin)], forState: UIControlState.Normal)
        UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName : UIFont.systemFontOfSize(23.0, weight: UIFontWeightThin), NSForegroundColorAttributeName: UIColor.whiteColor()]
    } else {
        // Fallback on earlier versions
    }

    if #available(iOS 9.0, *) {
        UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.self]).tintColor = UIColor.whiteColor()
        UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.self]).setTitleTextAttributes([NSFontAttributeName : UIFont.systemFontOfSize(16.0, weight: UIFontWeightThin)], forState: UIControlState.Normal)
    } else {
        // Fallback on earlier versions

    }

i have few issues below :-

  1. I am not able to set navigation bar color for share activity - Skype, inbox (Gmail mail app) on UIActivityViewController
  2. Not able to set barButtonItem e.g. "Cancel" font & size using UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.self]).setTitleTextAttributes([NSFontAttributeName : UIFont.systemFontOfSize(16.0, weight: UIFontWeightThin)], forState: UIControlState.Normal)

I tried to write same code in completion block for UIActivityViewController but nothing works.

  1. When i select a chat from Recent Chats on whatsapp share activity, the barbuttonitem color turns to default blue - See Snapshot enter image description here

  2. Above all, the solutions i used support iOS version 8.0, 8.2 or higher. I want to achieve all the same for versions starting from 7.0 or 7.1 . How can i do it ?

Upvotes: 2

Views: 1623

Answers (1)

user5938635
user5938635

Reputation:

// Navigation bar appearance (background and title)

[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor titleColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"FontNAme" size:titleSize], NSFontAttributeName, nil]];

[[UINavigationBar appearance] setTintColor:[UIColor barColor]];

// Navigation bar buttons appearance

[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor textBarColor], NSForegroundColorAttributeName, shadowColor, NSShadowAttributeName, [UIFont fontWithName:@"FontName" size:titleSize], NSFontAttributeName, nil];

Upvotes: 1

Related Questions