tvOS - Change color of navigation item's title - uinavigationitem

In iOS I used to change color of the navigation item's title using this code:
[self.navigationController.navigationBar setTitleTextAttributes:#{UITextAttributeTextColor:[UIColor whiteColor]}];
but in tvOS I get the error:
UITextAttributeTextColor is unavailable: not available in tvOS
Any work around to solve this issue?

Have you tried NSForegroundColorAttributeName instead of UITextAttributeTextColor?
UITextAttributeTextColor was deprecated in iOS7.

Related

tvOS: customising UINavigationBar fonts

Ive been trying to customize the fonts used in a UINavigationBar in a tvOS app and I'm having problems with getting the font change to work. Here is my code:
CGFloat fontSize = ((UIFont *)self.navigationBar.titleTextAttributes[NSFontAttributeName]).pointSize;
NSDictionary *appearance = #{
NSFontAttributeName : [UIFont fontWithName:#"HelveticaNeue-UltraLight" size:fontSize * 2],
NSForegroundColorAttributeName: [UIColor greenColor]
};
// Navigation bar Title
// Using traits - works in iOS only
UITraitCollection *traits = [UITraitCollection traitCollectionWithUserInterfaceIdiom:[[UIDevice currentDevice] userInterfaceIdiom]];
[[UINavigationBar appearanceForTraitCollection:traits] setTitleTextAttributes:appearance];
// Nav bar appearance - works in iOS only
[[UINavigationBar appearance] setTitleTextAttributes:appearance];
// Direct setting - works in iOS & tvOS
[self.navigationBar setTitleTextAttributes:appearance];
// Navigation bar Edit button
// Appearance - works in iOS only
[[UIBarButtonItem appearance] setTitleTextAttributes:appearance forState:UIControlStateNormal];
// Direct - works in iOS only
[self.editButtonItem setTitleTextAttributes:appearance forState:UIControlStateNormal];
So far it appears that I can either directly set the font and colour of the title in iOS. But an only use direct setting in tvOS.
For my edit button, I simply cannot get anything to work in tvOS.
I was hoping to use the appearance proxies either directly or via traits.
Anyone know why this is not working in tvOS?
I can't seem to find much on the inter webs about customizing the appearance of tvOS apps.
P.S. I'm using XCode 7.3.1 and tvOS 9.2

Navigationbar white tintcolor looks gray

I am developing an application which supports iOS 7 and later, using navigationbar with bartintcolor of "green color". However, I got a problem when setting "tintcolor" to white. It became gray color instead of white (as shown in the image below).
Thanks,
I had the same problem and spent lots of time figuring it out.
Go to iOS Settings > General > Accessibility > Increase Contrast.
Turn off "Darken Colors" switch.
please add code below to your appdelegate file
[[UINavigationBar appearance] setTitleTextAttributes:#{ UITextAttributeTextColor: [UIColor whiteColor],UITextAttributeFont: [UIFont fontWithName:#"FONT_NAME" size:15] }];

How to change the default grey icon colors for tabBarItems in iOS 7?

I've searched and tried all the possible solutions to no avail. All I want is to change the unselected default grey color to something darker. I'm using Xcode 5 and iOS 7. Would someone help?
(I tried all of these and more: How can I change the text and icon colors for tabBarItems in iOS 7?)
realtyTypeTabBar.selectedImageTintColor = [UIColor colorWithRed:206.0/256.0 green:221.0/256.0 blue:166.0/256.0 alpha:1];
[realtyTypeTabBar setSelectionIndicatorImage:[UIImage emptyImageWithSize:itemSize andBackgroundColor:[UIColor colorWithRed:84.0/256.0 green:115.0/256.0 blue:0 alpha:1]]];
for(UITabBarItem* item in realtyTypeTabBar.items)
{
item.image = [item.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[item setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]} forState:UIControlStateNormal];
[item setTitleTextAttributes:#{NSForegroundColorAttributeName : realtyTypeTabBar.tintColor} forState:UIControlStateSelected];
}
you can use story board to change that so easy you just need to select TabBar in the tabBarController in the story board and and in the show identity inspector in the user Defined Runtime Attributes add "unselectedItemTintColor" and change the type to the color and then you can choose the color that you want just like a photo

Change MFMailComposeViewController's UINavigationBar color in iOS7

I am trying to update my app for iOS7, however I am unable to set the colour of the UINavigationBar at the top of the screen. I have tried the classic approach...
[mailer.navigationBar setTintColor:[UIColor darkGreyColour]];
...however it didn't work. I have also tried calling setBarTintColor instead, however that didn't seem to work either.
Does anyone know if its possible to set the colour and if so how?
I had your same problem when updating my application for iOS 7.
I solved using this line of code (if you use images):
[[UINavigationBar appearance] setBackgroundImage:#"myImage" forBarPosition:UIBarPositionTopAttached barMetrics:UIBarMetricsDefault];
or this one if you are not using images:
[[UINavigationBar appearance] setBarTintColor:[UIColor blueColor]];
I placed then in AppDelegate, just before returning application:didFinishLaunchingWithOptions:
Hope this helps!
Try changing the tint in storyboard. Its in 'view' sub section when you select navigation bar in IB.

UINavigationBar tint color flashing in iOS 4

The app I'm working on has a custom nab bar but supports iOS 4.2-iOS 5, so I need to set the UINavigationBar background and tint in this old school way in my app delegate.
#implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
self.tintColor = [UIColor colorWithRed:42.0/255.0
green:164.0/255.0
blue:182.0/255.0
alpha:1.0];
UIImage *img = [UIImage imageNamed:#"navbar_bg.png"];
[img drawInRect:CGRectMake(0.0, 0.0,
self.frame.size.width,
self.frame.size.height)];
}
#end
This works for the most part, but I noticed when the app is first starting, the UIBarButtonItems flash the default navigation bar color for a second before they correct themselves and change color to match the navigation bar. Interestingly, the navigation bar itself uses the background image correctly from the get-go.
To be clear, I'm using setBackgroundImage for UINavigationBar on iOS 5 devices which works as expected so the flash is only in iOS 4.
Anyone have any insight on why this would happen and/or how to fix it?
The bar button items are the wrong color? You can manually set their tint color in viewDidLoad: to the tint color
navigationBar.rightBarButtonItem.tintColor = [UIColor ...]
if you're using a nib file. Otherwise you can do the same thing in loadView: . Either way this code will get executed as part of the initial draw loop so you'll have the proper color without any flashing.
Also for future reference, it's technically incorrect to override a method inside a category. (The latest version of Xcode, 4.3, will give you a warning about this). You should either properly subclass UINavigationBar or do "method swizzling". But that's pretty tough so don't worry about it right now :)
If you call the class with the code referenced in viewDidLoad try moving it to awakeFromNib