バーの様々なタイプのiOSのカスタムプロパティ

  iOSアプリケーションの開発では、多くの場合、あなたは同じテーマをバーナビゲーションバーとタブを設定する必要があり、設定するための一つ一つは、それはあまりにも面倒である、背景、フォントやナビゲーションバーとタブバー内のすべてのアプリケーションの他の属性を設定することに同意することができます。

  以下のような:UINavigationControllerクラスですべてNavigationController UINavigationControllerを継承し、クラスメソッドを適用し、その後、「UINavigationController」共通の親クラスから継承したクラスを作成します

ナビゲーションバーのプロパティが設定されている、プロジェクトがすべてナビゲーションコントローラの動作になります初期化

  次のようにサンプル・コードは次のとおりです。

1 +(ボイド)を初期化
 2  {
 3。     
4。 #warningは   UITabBarカラーモードUITabBarトピックボタンを設定することにより修飾することができる
 5。      UITabBarタブバー* = [UITabBar外観];
 6      NSMutableDictionary tabAttrs * = [NSMutableDictionary辞書];
 7      tabAttrs [UITextAttributeTextColor ] = [UIColor orangeColor];
 8は、     [タブバーsetTintColor:[UIColor orangeColor];
 9      
10      // 。UINavigationBar設け1 
。11      UINavigationBarナビゲーションバー* = [UINavigationBar外観];
 12は 
13である     
14      
15      //1.1ステータスバーセット
16      [sharedApplicationのUIApplication] .statusBarStyle = UIStatusBarStyleBlackOpaqueと、
 17。     
18である     // 背景画像を設定1.2 
19。          [ありsetBackgroundImageナビゲーションバー:[UIImage imageWithName:"@ navigationbar_background " ] forBarMetrics:UIBarMetricsDefault];
 20である   
21は     
22であり、     // フォントの設定1.3。
23は      NSMutableDictionary ATTRS * = [NSMutableDictionary辞書];
 24      ATTRS [UITextAttributeTextColor] = [UIColor blackColor];
 25      ATTRS [UITextAttributeTextShadowOffset] = [NSValue valueWithCGSize:CGSizeMake(00 )];
 26である      ATTRS [UITextAttributeFont] = [UIFont systemFontOfSize:20である]、
 27  
28      [ナビゲーションバーsetTitleTextAttributes:ATTRS];
 29      
30      // 2は、ナビゲーションボタンに関連する提供され
31がある      UIBarButtonItemクラスbarItem * = [UIBarButtonItemクラス外観];
 32      // 2.1背景は、図に配置された
33である      [:[UIImage imageWithName barItem setBackButtonBackgroundImage "@ navigationbar_button_background " ;] forState:UIControlStateNormal barMetrics UIBarMetricsDefault]
 34である      [barItem setBackButtonBackgroundImage:[UIImage imageWithName:@ "navigationbar_button_background_pushed " ] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
 35      [barItem setBackButtonBackgroundImage:[UIImage imageWithName:@" navigationbar_button_background_disable ] forState:UIControlStateDisabled barMetrics:UIBarMetricsDefault];
 36      // 2.2设置字体属性
37      NSMutableDictionary * itemAttrs = [NSMutableDictionary辞書]。
 38  
39      itemAttrs [UITextAttributeTextColor] = iOS7?[UIColor orangeColor]:[UIColor blackColor];
 40      itemAttrs [UITextAttributeTextShadowOffset] = [NSValue valueWithCGSize:CGSizeMake(00 )]。
41      itemAttrs [UITextAttributeFont] = [UIFont systemFontOfSize:14 ]。
42      [barItem setTitleTextAttributes:itemAttrs forState:UIControlStateNormal]。
43 }

 

ます。https://www.cnblogs.com/pretty-guy/p/4083604.htmlで再現

おすすめ

転載: blog.csdn.net/weixin_33811961/article/details/93199890