首页 文章

在iOS 7中,在UINavigation栏中设置BarButtonItem的蓝色文本颜色失败

提问于
浏览
0

我正在尝试在运行时更改Navbar色调,我可以更改导航栏色调,但是然后左右按钮(iOS 7上的系统蓝色)发生了变化,所以我试图强制它们回到系统蓝色 . 这是我正在使用的代码,从viewDidLoad调用:我已经尝试了NSForegroundColorAttributeName和UITextAttributeTextColor,但我不断获得白色或黑色文本,具体取决于导航栏的颜色 .

如何让按钮显示蓝色文字?

NSDictionary *btnAttr =   [NSDictionary dictionaryWithObjectsAndKeys:
                               [UIFont boldSystemFontOfSize:14], UITextAttributeFont,
                               [UIColor blueColor], NSForegroundColorAttributeName,
                               nil];
    for(UIView *v in [theView.view allSubViews])
    {
        if([v isKindOfClass:[UINavigationItem class]])
        {
            UINavigationItem *btn = (UINavigationItem *)v;
            [btn.leftBarButtonItem setTitleTextAttributes:btnAttr forState:UIControlStateNormal];
            [btn.rightBarButtonItem setTitleTextAttributes:btnAttr forState:UIControlStateNormal];
        }
    }

1 回答

  • 4

    在iOS7中,如果需要更改navigationBar按钮颜色,则需要设置 tintColor

    navigationController.navigationBar.tintColor = [UIColor blueColor];
    

    为了更好地理解,请查看下图:

    enter code here

相关问题