iOS菜鸟开发 导航栏主题--自定义颜色

1、给每个子控制器添加导航栏

/**

 *  初始化一个子控制器

 *

 *  @param child               需要初始化的子控制器

 *  @param title               标题

 *  @param imageName           未选中图标

 *  @param selectedImageName   选中的图标

 */

- (void)setupOneChildVC:(UIViewController *)child title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName

{

    //设置标题

    child.tabBarItem.title = title;

      //设置图片

    child.tabBarItem.image = [UIImage imageNamed:imageName];

    //设置选中的 图片

    child.tabBarItem.selectedImage = [UIImage imageNamed:selectedImageName];

    //添加导航栏

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:child];

    // 添加子控制器

    [self addChildViewController:nav];

}

2、自定义导航控制器

新建  NavigationController 继承 UINavigationController

//设置导航栏主题

+(void)initialize

{

   [self setupNavTheme];

}

+(void)setupNavTheme

{

  // 获得appearance 对象,就能修改主题

  UINavigationBar *navBar = [UINavigationBar appearance];

 

   //  *******  导航栏的颜色  *******

    navBar.barTintColor = GLThemeColor;     //自定义颜色

 

     //设置文字颜色

//    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];

//    textAttrs[UITextAttributeTextColor] = [UIColor blackColor];

//    设置字体大小

//    textAttrs[UITextAttributeFont] = [UIFont boldSystemFontOfSize:10];

 

}

 

posted @ 2016-01-21 17:40  悠扬007  阅读(245)  评论(0编辑  收藏  举报