1 、统一设置nav标题样式:
- (void)_setNavigationTitle { NSDictionary *navigationParams = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont fontWithName:@"FZLBJW--GB1-0" size:18]}; [[UINavigationBar appearance]setTitleTextAttributes:navigationParams]; }
2 、统一设置nav相关颜色:
- (void)_setNavigationColor { [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]]; [[UINavigationBar appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"FZLBJW--GB1-0" size:18],NSForegroundColorAttributeName:[UIColor blackColor]}]; [[UINavigationBar appearance] setTintColor:[UIColor blackColor]]; }
3 、统一设置返回按钮:
- (void)_setNavigationBackItem { UINavigationBar * navigationBar = [UINavigationBar appearance]; UIImage *image = [UIImage imageNamed:@"back"]; image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; navigationBar.backIndicatorImage = image; navigationBar.backIndicatorTransitionMaskImage = image; UIBarButtonItem *buttonItem = [UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]; UIOffset offset; offset.horizontal = - 500; offset.vertical = 0;//不为0在iOS11会造成视图错乱 [buttonItem setBackButtonTitlePositionAdjustment:offset forBarMetrics:UIBarMetricsDefault]; }
4 、统一设置tableViewCell的分割线:
- (void)_setTableViewAppearace { [[UITableView appearance]setTableFooterView:[UIView new]]; [[UITableView appearance]setSeparatorInset:UIEdgeInsetsZero]; }
5 、统一设置SegmentedControl
UISegmentedControl *appearance = [UISegmentedControl appearance]; //Segmenteg正常背景 [appearance setBackgroundImage:[UIImage imageNamed:@"Segmente.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; //Segmente选中背景 [appearance setBackgroundImage:[UIImage imageNamed:@"Segmente_a.png"] forState:UIControlStateSelected barMetrics:UIBarMetricsDefault]; //Segmente左右都未选中时的分割线 //BarMetrics表示navigation bar的状态,UIBarMetricsDefault 表示portrait状态(44pixel height),UIBarMetricsLandscapePhone 表示landscape状态(32pixel height) [appearance setDividerImage:[UIImage imageNamed:@"Segmente_line.png"] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; [appearance setDividerImage:[UIImage imageNamed:@"Segmente_line.png"] forLeftSegmentState:UIControlStateSelected rightSegmentState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; [appearance setDividerImage:[UIImage imageNamed:@"Segmente_line.png"] forLeftSegmentState:UIControlStateNormal rightSegmentState:UIControlStateSelected barMetrics:UIBarMetricsDefault]; //字体 NSDictionary *textAttributes1 = @{UITextAttributeFont: [UIFont systemFontOfSize:18], UITextAttributeTextColor: [UIColor blueColor], UITextAttributeTextShadowColor: [UIColor whiteColor], UITextAttributeTextShadowOffset: [NSValue valueWithCGSize:CGSizeMake(1, 1)]}; [appearance setTitleTextAttributes:textAttributes1 forState:1]; NSDictionary *textAttributes2 = @{UITextAttributeFont: [UIFont systemFontOfSize:18], UITextAttributeTextColor: [UIColor whiteColor], UITextAttributeTextShadowColor: [UIColor blackColor], UITextAttributeTextShadowOffset: [NSValue valueWithCGSize:CGSizeMake(1, 1)]}; [appearance setTitleTextAttributes:textAttributes2 forState:0];
6 、统一设置BarButton
//修改导航条上的UIBarButtonItem UIBarButtonItem *appearance = [UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil nil]; //设置导航栏的字体包括backBarButton和leftBarButton,rightBarButton的字体 NSDictionary *textAttributes = @{UITextAttributeFont: [UIFont systemFontOfSize:18], UITextAttributeTextColor: [UIColor blueColor], UITextAttributeTextShadowColor: [UIColor whiteColor], UITextAttributeTextShadowOffset: [NSValue valueWithCGSize:CGSizeMake(1, 1)]}; [appearance setTitleTextAttributes:textAttributes forState:1];//forState为0时为下正常状态,为1时为点击状态。 //修改leftBarButton,rightBarButton背景效果 [appearance setBackgroundImage:[UIImage imageNamed:@"navBarButton.png"] forState:UIControlStateNormal style:UIBarButtonItemStyleBordered barMetrics:UIBarMetricsDefault]; [appearance setBackgroundImage:[UIImage imageNamed:@"navBarButton_a.png"] forState:UIControlStateHighlighted style:UIBarButtonItemStyleBordered barMetrics:UIBarMetricsDefault]; //backBarButton需要单独设置背景效果。只能在ios6.0以后才能用 [appearance setBackButtonBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forState:0 barMetrics:UIBarMetricsDefault]; [appearance setBackButtonBackgroundImage:[UIImage imageNamed:@"work.png"] forState:1 barMetrics:UIBarMetricsDefault]; [appearance setBackButtonTitlePositionAdjustment:UIOffsetMake(2, -1) forBarMetrics:UIBarMetricsDefault];
7 、统一设置工具栏:
UIToolbar *appearance = [UIToolbar appearance]; //样式和背景二选一即可,看需求了 //样式(黑色半透明,不透明等)设置 [appearance setBarStyle:UIBarStyleBlackTranslucent]; //背景设置 [appearance setBackgroundImage:[UIImage imageNamed:@"toolbarBg.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
8 、统一设置系统View的tintColor:
关于tintColor的介绍请移步:https://www.jianshu.com/p/4bcaf6349133
UIView.appearance().tintColor = UIColor(named: "Deep Carmine Pink")
你会发现系统默认的颜色从蓝色变为了 Deep Carmine Pink!(backBarItem也是红色只是被覆盖层改变了)