Change the color of a bar button in iOS 7

不打扰是莪最后的温柔 提交于 2019-12-04 19:40:46

You have to set the tintColor property on the button after you assign the button.

self.navigationItem.rightBarButtonItem = nextButton;
self.navigationItem.rightBarButtonItem.tintColor = [UIColor blueColor];

instead of

self.navigationItem.rightBarButtonItem.tintColor = [UIColor blueColor];
self.navigationItem.rightBarButtonItem = nextButton;
shannoga

If you wish to have the same color for all bar buttons you can use the following line of code:

self.window.tintColor = [UIColor redColor];

in your app delegate.

Try below code you can set color of button as well text color

UIView *customBarButtonView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 30)];

UIButton *buttonDone = [UIButton buttonWithType:UIButtonTypeSystem];
[buttonDone addTarget:self action:@selector(doneButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

buttonDone.backgroundColor = [UIColor redColor];
   // or try this one
// buttonDone.tintColor = [UIColor redColor];

buttonDone.frame = CGRectMake(10, 0, 50, 30);

buttonDone.titleLabel.textColor = [UIColor colorWithRed:141.0/255.0 green:209.0/255.0 blue:205.0/255.0 alpha:1.0];
buttonDone.titleLabel.font = [UIFont fontWithName:@"SourceSansPro-Light" size:20.0f];
[buttonDone setTitle:@"Done" forState:UIControlStateNormal];
[customBarButtonView addSubview:buttonDone];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:customBarButtonView];

working code.. try this.

UIImage *image = [UIImage imageNamed:@"Image.png"];
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
self.navigationItem.leftBarButtonItem = menuButton;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!