Reputation: 311
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 :-
UIActivityViewController
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.
When i select a chat from Recent Chats on whatsapp share activity, the barbuttonitem color turns to default blue -
See Snapshot
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
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