iOS 更改tabbar字体颜色 自定义controller返回按钮

   改变系统的tabbar字体颜色:

//设置你想要显示的颜色

 NSDictionary *dictHome = [NSDictionary dictionaryWithObject:MAIN_TABBAR_COLOR forKey:NSForegroundColorAttributeName];
    [navCtr.tabBarItem setTitleTextAttributes:dictHome forState:UIControlStateSelected];
这种是单个设置, 如果想全局设置,可以这样:

    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:11], NSFontAttributeName,COLOR_NOSELETED,NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:11], NSFontAttributeName,COLOR_SELECTED,NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];

根据自己的需要,选择合适的方式进行设置;

从这篇文章中学习了: 

http://www.jianshu.com/p/e61c096753eb



如果不行使用系统的返回按,想使用自定义的按钮:

扫描二维码关注公众号,回复: 2243801 查看本文章

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 60, 44);

    [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateNormal];

    [button setImage:[UIImage imageNamed:@"icon_back"] forState:UIControlStateHighlighted];

    
    button.contentEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0);
    [button addTarget:self action:@selector(backButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem = item;

按钮的具体大小和位置,可以自己调整.  如果不想在每个controller里的都写,建一个父类,在父类中写这个; 

猜你喜欢

转载自blog.csdn.net/xfy6238/article/details/78591994