Color of UIToolbar not changing

时间秒杀一切 提交于 2019-12-06 02:10:31

问题


I have created a UIToolbar. I am trying to give it black color using:

toolbar.barStyle = UIBarStyleBlackOpaque;

or

toolbar's background property. But its color does not change in either case.

How can I change it?


回答1:


Have you tried setting the tint property on UIToolbar? ie:

- (void)viewDidLoad {
  [super viewDidLoad];
  UIToolbar *toolbar=[[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 46)];
  toolbar.tintColor=[UIColor redColor];
  [self.view addSubview:toolbar];
  [toolbar release];
}

Detailed in the apple docs




回答2:


IN iOS 7 you need to set the barTintColor Property-

UIToolbar *doneToolbar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 584, 320, 44)];
doneToolbar.translucent=NO;
doneToolbar.barTintColor=[UIColor redColor];
[self.view addSubview:doneToolbar];

I have used it its working fine...




回答3:


Use this after you allocate and initialize you toolbar object:

toolbar.tintColor = [UIColor darkGrayColor];

Hope this helps you.




回答4:


On IOS 10, apparently we also need to call sizeToFit on the UIToolBar to change the background color:

This worked for me:

let dummyToolbar = UIToolbar()
dummyToolbar.barTintColor = .lightGray
dummyToolbar.sizeToFit() // without this line it doesn't work


来源:https://stackoverflow.com/questions/5581644/color-of-uitoolbar-not-changing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!