[英]Change navigation bar tint color iOS 7.
我知道如何在iOS 6中更改導航棒色調顏色:
[UINavigationBar appearance].tintColor = [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0];
我在APPDelegate頁面中添加此代碼。 現在我想在iOS 7中執行此操作,但上面的代碼無效。 我在網上搜索。 我有一個解決方案。 通過在每個頁面添加以下功能,我可以更改導航顏色。
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0];
但我需要一個可以添加到APPDelegate功能的功能。 請幫我解決這個問題。
為什么不使用setBarTintColor
作為外觀代理,你可以這樣做:
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
{
[[UINavigationBar appearance] setTintColor: [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0]];
}
else
{
[[UINavigationBar appearance] setBarTintColor: [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0]];
}
你可以在appdelegate.m中添加以下代碼
if your app is navigation based
// for background color
[nav.navigationBar setBarTintColor:[UIColor blueColor]];
// for change navigation title and button color
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"FontNAme" size:20], NSFontAttributeName, nil]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
使用respondsToSelector進行版本檢查可能會更好。
if ([self.navigationBar respondsToSelector:@selector(setBarTintColor:)]) {
[self.navigationBar setBarTintColor: [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0]];
} else {
[self.navigationBar setTintColor: [UIColor colorWithRed:129/255.0 green:200/255.0 blue:244/255.0 alpha:1.0]];
}
在Swift中,對我來說,當電子郵件彈出時,我想更改“取消”和“發送”按鈕的色調顏色。 而且效果很好。
(UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.self])).tintColor = UIColor.whiteColor()
試試[self.navigationController.navigationBar setTranslucent:NO];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.