tvOS: customising UINavigationBar fonts - objective-c

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

Related

iOS 9: Background Image for UINavigationBar not working

I have a global background image (basically some orange color) which is set for all navigation bars inside the AppDelegate:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"order-navbar"] forBarMetrics:UIBarMetricsDefault];
This works for all views except one: I have an MFMailComposeViewController whose navigation bar background stays white-gray no matter what I do:
let mailController = MFMailComposeViewController()
mailController.navigationBar.tintColor = UIColor.whiteColor() // this works
emailController.navigationBar.setBackgroundImage(UIImage(named: "order-navbar") forBarMetrics:UIBarMetrics.Default) // this does not
UINavigationBar.appearance().setBackgroundImage(UIImage(named: "order-navbar") forBarMetrics:UIBarMetrics.Default) // this does neither
However, sometimes the mail controller appears at first with the orange bar and then suddenly changes its color to white-gray again.
On iOS 8 everything works. Is this an iOS 9 bug?

UINavigationBar color has changed after upgrading to latest Xcode

Recently I've updated my Xcode IDE to the latest to have iOS 7.1 SDK. For some reason, after recompiling my app with the new Xcode I get this wired UINavigationBar background colour.
I'm using storyboard to push the secondary view controller from home screen. The secondary view controller is a static table of settings, also built using storyboard, and contains the following code in its viewDidLoad method:
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage = nil;
I haven't done any other changes to this screen or any other screens in the app.
This is how it used to look like before:
This is how it is look like now:
Does anyone have any idea what could have caused this?
Cheers,
EDIT: #Leo Natan -
When I'm trying to set the color myself, for example, by replacing this line:
[self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
with this line:
[self.navigationController.navigationBar setBackgroundColor:[UIColor redColor]];
I get this: the red color applied only on the header without the status bar, what can I do?
Latest Xcode comes with iOS7.1 SDK, in which Apple once again changed how the color is calculated. You will have to play again with your color to achieve a similar look in iOS7.1.
Maybe you should take another approach. Use the Appearance Proxy in the - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions. Thats how I do it:
//Navigationbar
[[UINavigationBar appearance] setBarTintColor:lightOrangeColor];
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:#"navbarAssets-backArrow-iOS7"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:#"navbarAssets-backArrow-iOS7"]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes: #{NSForegroundColorAttributeName : [UIColor whiteColor]}];

SKStoreProductViewController title color

How do you change the title color and/or bar tint color in a SKStoreProductViewController?
I'm using the appearance API to set navigation bars to a dark color and the text to white. It changes the title color but not the bar tint color in my SKStoreProductViewController.
I don't think you can. At least not on iOS 7. On iOS 6 you can use the UIAppearance protocol and the SKSPVC will pick up the appearance you set on the UINavigationBar.
As noted on this thread, the SKSPVC is a remote view controller so it's inaccesible programmatically, meaning that you can't set it's appearance directly (or indirectly?).
Do the following to avoid the SKStoreProductViewController to take over a tintColor of value WHITE:
#define kCOLOR_NON_WHITE_COLOR [UIColor darkGrayColor]
// CHANGE ALL TINTING BEFORE WE CREATE An INSTANCE OF THIS BROKEN PIECE
[UIWindow appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
[UIView appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
[UINavigationBar appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
[UIBarButtonItem appearance].tintColor = kCOLOR_NON_WHITE_COLOR;
// NOW CREATE THE THING
SKStoreProductViewController *controller = [[[SKStoreProductViewController alloc] init] autorelease];
This draws all the UIBarButtonItems and the UISegmentedControls in this controller in the defined color AFAIK and thus makes the controller more like your apps design.
IMPORTANT: Just do not forget(!!!) to change all the tinting back after you dismissed this controller, otherwise fresh created views in your app might take over the enforced tinting.
UPDATE: As you might already have found out the following to manipulate the appearance does not work:
[UINavigationBar appearanceWhenContainedIn:[SKStoreProductViewController class], nil]
This fix is for iOS 7 & 8 on iOS 6 you have different issues. =)

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

IOS 6 navigationController navigationbar

I just updated my phone to IOS 6 but I have some issue regarding adding UIImageView on the UINavigationController navigationbar. This is my code
UIImage *logoImage = [UIImage imageNamed:#"navigationbar.png"];
UIImageView *logoImageView = [[UIImageView alloc] initWithImage:logoImage];
UINavigationBar *navBar = self.navigationController.navigationBar;
[navBar addSubview:logoImageView];
[logoImageView release];
This will add logo on navigationbar, it works great on the lower version of IOS 6. But on IOS 6 the logo shown but the back button was behind the logo so back button is not shown.
I don't want to override the UINavigationBar drawrect since I also have UINavigatioBar somewhere on the code for popup.
Any suggestions?
I think you don't need a UIImageView in IOS 6.
You can just put a background image in the UINavigationBar (for example in AppDelegate) like this:
[[UINavigationBar appearance] setBackgroundImage :[UIImage imageNamed:#"navigationbar"]];
Found a good site which explains some new user interface customisation in IOS 6:
click here