[iOS微博項目,[iOS博項目
A.導覽列兩側文字按鈕1.需求:所有導覽列兩側的文字式按鈕統一樣式普通樣式:橙色高亮樣式:紅色不可用樣式:亮灰陰影:不使用字型大小:15 github: https://github.com/hellovoidworld/HVWWeibo 2.實現效果預設樣式: 1 /** 類初始化的時候調用 */ 2 + (void)initialize { 3 // 初始化導覽列樣式 4 [self initNavigationBarTheme]; 5 6 // 初始化導覽列item樣式 7 [self initBarButtonItemTheme]; 8 } 9 10 /** 統一設定導覽列item的樣式 11 * 因為是通過主題appearence統一修改所有NavivationBar的樣式,可以使用類方法12 */13 + (void) initBarButtonItemTheme {14 // 設定導覽列,修改所有UINavigationBar的樣式15 UIBarButtonItem *appearance = [UIBarButtonItem appearance];16 17 // 設定noraml狀態下的樣式18 NSMutableDictionary *normalTextAttr = [NSMutableDictionary dictionary];19 // 字型大小20 normalTextAttr[NSFontAttributeName] = [UIFont systemFontOfSize:15];21 // 字型顏色22 normalTextAttr[NSForegroundColorAttributeName] = [UIColor orangeColor];23 // 設定為normal樣式24 [appearance setTitleTextAttributes:normalTextAttr forState:UIControlStateNormal];25 26 // 設定highlighted狀態下的樣式27 NSMutableDictionary *highlightedTextAttr = [NSMutableDictionary dictionaryWithDictionary:normalTextAttr];28 // 字型顏色29 highlightedTextAttr[NSForegroundColorAttributeName] = [UIColor redColor];30 // 設定為normal樣式31 [appearance setTitleTextAttributes:highlightedTextAttr forState:UIControlStateHighlighted];32 33 // 設定disabled狀態下的樣式34 NSMutableDictionary *disabledTextAttr = [NSMutableDictionary dictionaryWithDictionary:normalTextAttr];35 // 字型顏色36 disabledTextAttr[NSForegroundColorAttributeName] = [UIColor lightGrayColor];37 // 設定為normal樣式38 [appearance setTitleTextAttributes:disabledTextAttr forState:UIControlStateDisabled];39 40 } B.設定導覽列樣式1.需求:
- 統一顯示文字顏色:黑色
- 文字陰影:禁止
- 字型大小:20
1 /** 統一設定導覽列樣式 */ 2 + (void) initNavigationBarTheme { 3 // 使用appearence(主題)設定,統一修改所有導覽列樣式 4 UINavigationBar *appearance = [UINavigationBar appearance]; 5 6 // 為了統一iOS6和iOS7,iOS6需要設定導覽列背景來類比iOS7的效果 7 if (!iOS7) { 8 [appearance setBackgroundImage:[UIImage imageWithNamed:@"navigationbar_background"] forBarMetrics:UIBarMetricsDefault]; 9 }10 11 // 設定屬性12 NSMutableDictionary *attr = [NSMutableDictionary dictionary];13 // 設定字型14 attr[NSForegroundColorAttributeName] = [UIColor blackColor];15 attr[NSFontAttributeName] = [UIFont systemFontOfSize:20];16 // 消去文字陰影,設定陰影位移為017 NSShadow *shadow = [[NSShadow alloc] init];18 shadow.shadowOffset = CGSizeZero;19 attr[NSShadowAttributeName] = shadow;20 21 [appearance setTitleTextAttributes:attr];22 }