[UINavigationBar appearance]與[UIBarButtonItem appearance]使用方法基本相同。
- [UIBarButtonItem appearance] 設定導覽列左右兩邊item的文字樣式
-
[UINavigationBar appearance] 設定導覽列title,整個導覽列顔色背景等
方法總結:
UINavigationBar:
-
1.設定顔色 [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0 green:0 blue:0 alpha:1]]; [[UINavigationBar
appearance] setBarTintColor:UIColorFromRGB(0x067AB5)];
- 2.設定導航文字顔色 [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
- 3.設定導航背景 [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@”nav_bg.png”] forBarMetrics:UIBarMetricsDefault];
UIBarButtonItem:
-
1.修改背景: [[UIBarButtonItem appearance] setBackButtonBackgroundImage:leftButton
forState:0
barMetrics:UIBarMetricsDefault];
-
2.修改字型,陰影,字型顔色 NSDictionary* textAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
BAR_BUTTON_TITLE_TEXT_COLOR,UITextAttributeTextColor,
BAR_BUTTON_TITLE_FONT,UITextAttributeFont,
BAR_BUTTON_TITLE_SHADOW_COLOR,UITextAttributeTextShadowColor,
[NSValue valueWithCGSize:CGSizeMake(1, 1)],UITextAttributeTextShadowOffset,
nil]; [[UIBarButtonItem appearance] setTitleTextAttributes:textAttributes forState:0];
-
3.修改UIBarButtonItem中文字的位置: [[UIBarButtonItem appearance]
setBackButtonTitlePositionAdjustment:UIOffsetMake(2, -1)
forBarMetrics:UIBarMetricsDefault];