【问题标题】:Change colour of arrow in Back Button iOS更改后退按钮 iOS 中箭头的颜色
【发布时间】:2013-12-13 12:16:44
【问题描述】:

我正在尝试更改导航栏中后退按钮的箭头颜色。我已经能够更改文本颜色,但不能更改箭头。这是我更改文本颜色的代码:

[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                          [UIColor whiteColor], UITextAttributeTextColor,
                                                          nil] forState:UIControlStateNormal];

如果有人可以建议我如何更改箭头颜色,那将非常有帮助!

【问题讨论】:

    标签: ios ios7 uinavigationbar


    【解决方案1】:

    您可以使用这样的图像来更改后退按钮的背景:

    UIImage *buttonBack30 = [[UIImage imageNamed:@"button_back_textured_30"]
        resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)];
    UIImage *buttonBack24 = [[UIImage imageNamed:@"button_back_textured_24"]
        resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12, 0, 5)];
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack30
        forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
    [[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack24
        forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
    

    来源:RAYWENDERLICH

    如果你不想使用图片,你可以改变导航栏的tintcolor,因为它决定了bar button item的文本颜色:

    [[UINavigationBar appearance] setTintColor:[UIColor yourColor]];
    

    【讨论】: