如何更改ios7.0中的leftbarbuttonitem颜色

时间:2013-12-03 15:14:15

标签: ios7 uinavigationitem

    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];

我已经完成了上面的工作,但它不起作用。颜色仍然和背景颜色一样!

1 个答案:

答案 0 :(得分:3)

创建按钮并替换

   UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:self.leftBarButton];
    self.navigationItem.leftBarButtonItem = leftBarButton;

+ (UIBarButtonItem*)itemWithNormalImage:(UIImage*)normalImage
                           pressedImage:(UIImage*)pressedImage
                                 target:(id)target
                                 action:(SEL)action
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:normalImage
            forState:UIControlStateNormal];
    [button setImage:pressedImage
            forState:UIControlStateSelected];
    [button setImage:pressedImage
            forState:UIControlStateHighlighted];

    button.frame = CGRectMake(0, 0, normalImage.size.width, normalImage.size.height);
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* item=[[UIBarButtonItem alloc] initWithCustomView:button];
    return item;
}

文字颜色:

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"done" style:UIBarButtonItemStyleBordered target:self action:nil];
[item setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateNormal];
self.navigationItem.leftBarButtonItems = @[item];