navigationBarHidden和navigationBar.hidden的區(qū)別
? ? ? ?navigationBarHidden在官方文檔上的解釋是A Boolean value that indicates whether the navigation bar is hidden
navigationBar在官方文檔上的解釋是It is permissible to customize the appearance of the navigation bar using the methods and properties of the UINavigationBar class but you must never change its frame, bounds, or alpha values or modify its view hierarchy directly. To show or hide the navigation bar, you should always do so through the navigation controller by changing its navigationBarHidden property or calling the setNavigationBarHidden:animated: method.
意思就是說它可以通過UINavigationBar這個類的屬性來自定義的顯示navigation bar,但是你不能改變他的坐標(biāo),大小,透明度或者改變它的等級.為了展示或者隱藏navigation bar,你應(yīng)該通過改變navigationBarHidden屬性或者調(diào)取setNavigationBarHidden:animated:這個方法.
設(shè)置導(dǎo)航欄的背景顏色
在iOS 7中凌箕,不再使用tintColor屬性來設(shè)置導(dǎo)航欄的顏色至朗,而是使用barTintColor屬性來修改背景色冤荆。我們可以在AppDelegate.m文件中的方法didFinishLaunchingWithOptions:里面添加如下代碼來修改顏色:
[[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];
默認(rèn)情況下,導(dǎo)航欄的translucent屬性為YES,但是在一般的開發(fā)過程中設(shè)置為NO
[[UINavigationBar appearance] setTranslucent:NO];
在導(dǎo)航欄中使用背景圖片
如果希望在導(dǎo)航欄中使用一個圖片當(dāng)做背景肄鸽,那么你需要提供一個稍微高一點(diǎn)的圖片(這樣可以延伸到導(dǎo)航欄背后)卫病。導(dǎo)航欄的高度從44 points(88 pixels)變?yōu)榱?4 points(128 pixels)油啤。我們依然可以使用setBackgroundImage:方法為導(dǎo)航欄設(shè)置自定義圖片。如下代碼所示:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
定制返回按鈕的顏色
要想給返回按鈕著色蟀苛,可以使用tintColor屬性
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
如果想要用自己的圖片替換V型益咬,可以設(shè)置圖片的backIndicatorImage和backIndicatorTransitionMaskImage。如下代碼所示:
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"back_btn.png"]];
[[UINavigationBar?appearance]?setBackIndicatorTransitionMaskImage:[UIImage?imageNamed:@"back_btn.png"]];
修改導(dǎo)航欄標(biāo)題的字體
跟iOS 6一樣帜平,我們可以使用導(dǎo)航欄的titleTextAttributes屬性來定制導(dǎo)航欄的文字風(fēng)格幽告。在text attributes字典中使用如下一些key,可以指定字體裆甩、文字顏色冗锁、文字陰影色以及文字陰影偏移量:
UITextAttributeFont – 字體key
UITextAttributeTextColor – 文字顏色key
UITextAttributeTextShadowColor – 文字陰影色key
UITextAttributeTextShadowOffset – 文字陰影偏移量key
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor?=?[UIColor?colorWithRed:0.0?green:0.0?blue:0.0?alpha:0.8];
shadow.shadowOffset?=?CGSizeMake(0,?1);
[[UINavigationBar appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor?colorWithRed:245.0/255.0?green:245.0/255.0?blue:245.0/255.0?alpha:1.0],?NSForegroundColorAttributeName,
shadow,?NSShadowAttributeName,
[UIFont?fontWithName:@"HelveticaNeue-CondensedBlack"size:21.0],?NSFontAttributeName,?nil]];
修改電池電量條的風(fēng)格
第一種方法:在iOS 7中,我們可以在每個view controller中overridingpreferredStatusBarStyle
-(UIStatusBarStyle)preferredStatusBarStyle
{
returnUIStatusBarStyleLightContent;
}
第二種:在UIApplication的statusBarStyle方法來設(shè)置狀態(tài)欄嗤栓,不過冻河,首先需要停止使用View controller-based status bar appearance。在project target的Info tab中茉帅,插入一個新的key叨叙,名字為View controller-based status bar appearance,并將其值設(shè)置為NO
然后就可以使用下面的代碼來設(shè)置狀態(tài)欄風(fēng)格
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
隱藏狀態(tài)欄
- (BOOL)prefersStatusBarHidden
{
returnYES;
}