導(dǎo)航欄
1半透明
self.navigationController.navigationBar.translucent=NO;
2從導(dǎo)航欄下面開(kāi)始算坐標(biāo)
self.edgesForExtendedLayout=UIRectEdgeNone;
3設(shè)置全局的返回按鈕圖片。
在 AppDelegate 中進(jìn)行全局設(shè)置神僵,代碼如下:
UIImage *backImage = [[[UIImage imageNamed:@"navigation_back"]
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
imageWithAlignmentRectInsets:UIEdgeInsetsMake(0, 0, 11.5, 0)];
[[UINavigationBar appearance] setBackIndicatorImage:backImage];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backImage];
注:返回按鈕的圖片我采用的是44*44 point 的圖片纬向,但是不知道為什么如果直接設(shè)置就會(huì)偏上11.5 point涯雅,只好校正一下阁猜。
PS:UIAppearance.iOS5及其以后提供了一個(gè)比較強(qiáng)大的工具UIAppearance腹纳,我們通過(guò)UIAppearance設(shè)置一些UI的全局效果张症,這樣就可以很方便的實(shí)現(xiàn)UI的自定義效果又能最簡(jiǎn)單的實(shí)現(xiàn)統(tǒng)一界面風(fēng)格.
使用appearance設(shè)置UI效果最好采用全局的設(shè)置能庆,在所有界面初始化前開(kāi)始設(shè)置九杂,否則可能失效颁湖。
4隱藏返回按鈕上的文字
[[UIBarButtonItem appearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)?forBarMetrics:UIBarMetricsDefault];
其實(shí)就是把按鈕文字向上移了60 point,并沒(méi)有隱藏例隆,只是在屏幕上看不到而已甥捺,用 Reveal 還是可以看到……
5背景顏色
[UINavigationBar appearance].barTintColor = [UIColor blueColor];
6字體顏色
a)頂部標(biāo)題顏色
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
b)按鈕的文字顏色
[UINavigationBar appearance].tintColor = [UIColor whiteColor];
7navigation底部陰影
[[UINavigationBar appearance] setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[UIImage new]];
iOS10之前的navigationBar的背景是@"_UINavigationBarBackground",到iOS10變成了@"_UIBarBackground"镀层。
NSArray *subviews=self.navigationController.navigationBar.subviews;
for (UIView *view in subviews) {
? ? ? ?if (iOS10) {
? ? ? ? ? ? ? ?//iOS10,改變了狀態(tài)欄的類為_(kāi)UIBarBackground
? ? ? ? ? ? ? ?if ([view isKindOfClass:NSClassFromString(@"_UIBarBackground")]) {
? ? ? ? ? ? ? ? ? ? ? ? ? ?view.hidden = YES;
? ? ? ? ? ? ? ?}
? ? ? ? }else{
? ? ? ? ? ? ? ?//iOS9以及iOS9之前使用的是_UINavigationBarBackground
? ? ? ? ? ? ? ?if ([view isKindOfClass:NSClassFromString(@"_UINavigationBarBackground")]) {
? ? ? ? ? ? ? ? ? ? ? ? view.hidden = YES;
? ? ? ? ? ? ? ? }?
? ? ? ? ?}
}
標(biāo)簽欄
1字體顏色
[UITabBarItem.appearance setTitleTextAttributes:?@{ NSForegroundColorAttributeName : [UIColor blueColor] }
forState:UIControlStateNormal];
[UITabBarItem.appearance setTitleTextAttributes:?@{ NSForegroundColorAttributeName : [UIColor whiteColor] }
forState:UIControlStateSelected];
2隱藏標(biāo)簽欄
a)推薦方法
設(shè)置需要關(guān)閉的vc的hidesBottomBarWhenPushed屬性為yes
b)在viewwillappear中加入
self.tabBarController.tabBar.hidden=YES;
如果在viewdidload中加入镰禾,則會(huì)被覆蓋
3tabbar上方的線
[self.tabBarsetShadowImage:[[UIImagealloc]init]];
[self.tabBarsetBackgroundImage:[[UIImagealloc]init]];
ios10適配
//UITabBarController里面
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"BarBackground.png"];
[[UITabBar appearance] setShadowImage:[UIImage new]];
4半透明
[self.tabBarsetTranslucent:NO];
5設(shè)置常規(guī)圖片和選中圖片
a)常規(guī)圖片
UITabBarItem*item =self.tabBar.items[index];
UIImage*imageNomal = [[UIImageimageNamed:nomalImageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item.image= imageNomal;
b)選中圖片
UIImage*imageSelected = [[UIImageimageNamed:selectedImageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
item.selectedImage= imageSelected;
狀態(tài)欄
1改變狀態(tài)欄顏色
首先在 Info.plist 中的 Information Property List 中添加一個(gè) Key為View controller-based status bar appearance的 item,其 Type 設(shè)為 Boolean,Value 設(shè)為 NO
然后在AppDelegate.m的application:didFinishLaunchingWithOptions:中添加:
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
2隱藏狀態(tài)欄
首先在 Info.plist 中的 Information Property List 中添加一個(gè) Key為View controller-based status bar appearance的 item吴侦,其 Type 設(shè)為 Boolean屋休,Value 設(shè)為 NO
在需要隱藏StatusBar 的 ViewController 中的viewDidLoad加入以下代碼:
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
[self prefersStatusBarHidden];
[self setNeedsStatusBarAppearanceUpdate];
}
重寫(xiě)prefersStatusBarHidden:
-(BOOL)prefersStatusBarHidden {
return YES;
}
注:但是這樣設(shè)置的話從這個(gè)頁(yè)面開(kāi)始整個(gè) app 的 StatusBar 都會(huì)隱藏,如果想要再顯示出來(lái)备韧,只需要在其他 ViewController 中加入:
[UIApplication sharedApplication].statusBarHidden = NO;