修改NavigationBar样式

iOS Tip: Change Status Bar Icon & Text Colors

When iOS 7 was introduced Apple allowed your application to extend all the way up into the status bar region. This was neat because you can scroll content behind it, change the color, and make the entire screen feel completely full. One thing that has upset me is that it isn’t really straight forward as to how to change the color of the time, carrier, battery, and other icons that live in the status bar. So here is my quick tips.
Launch Screen Colors
In general you can just hide the status bar at launch, but if you want the time to overlay on it you will need to head into your Info.plist file. You will find a Status Bar entry and you simply need to change it to Light Content and then it will display white text and icons. Or set this info in you info.plist.

Inside UIViewControllers
Now inside the UIViewControllers are a bit different. We first want to style the tint and the bar tint of the navigation bar. I am goign to set it to a blue background with a white tint. I do this in my FinishedLaunching where I create my UINavigationController in the AppDelegate:
navigationController.NavigationBar.TintColor = UIColor.White;
navigationController.NavigationBar.BarTintColor = UIColor.FromRGB(52,152,219);

Now were are getting closer, but still have 2 issues.
The text is black

The status bar icons and text are black
NavigationBar Text Appearance
To fix the text we head back to our AppDelegate and we have to update the “TitleTextAttributes” of our UINavigationBar.Appearance:

UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes
{
TextColor = UIColor.White
});
view rawtext.cs hosted with ❤ by GitHub

Status Bar
From my findings teh status bar on each UIViewController is actually controlled separatelly, which is very annoying. We must update the NavigationBar.BarStyle and set it to the BlackStyle to get the desired white text and icons. I do this on the ViewDidLoad method.
NavigationController.NavigationBar.BarStyle = UIBarStyle.Black;

There you have it! A nice new themed iOS app. If you find a better way of doign this please let me know in the comments.
Xamarin.Forms!
If you are using Xamarin.forms you must also set the BarTextColor = Color.White on your NavigationPage! - See more at: http://motzcod.es/post/110755300272/ios-tip-change-status-bar-icon-text-colors#sthash.rUVotNJp.dpuf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值