[英]Color of UIToolbar not changing
I have created a UIToolbar. 我创建了一个UIToolbar。 I am trying to give it black color using: 我试图用它给它黑色:
toolbar.barStyle = UIBarStyleBlackOpaque;
or 要么
toolbar's background
property. 工具栏的background
属性。 But its color does not change in either case. 但它的颜色在任何一种情况下都不会改变。
How can I change it? 我该怎么改变它?
IN iOS 7 you need to set the barTintColor Property- 在iOS 7中,您需要设置barTintColor属性 -
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... 我用它工作正常......
Have you tried setting the tint property on UIToolbar? 您是否尝试在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];
}
On IOS 10, apparently we also need to call sizeToFit
on the UIToolBar
to change the background color: 在IOS 10上,显然我们还需要在sizeToFit
上调用UIToolBar
来改变背景颜色:
This worked for me: 这对我有用:
let dummyToolbar = UIToolbar()
dummyToolbar.barTintColor = .lightGray
dummyToolbar.sizeToFit() // without this line it doesn't work
Use this after you allocate and initialize you toolbar object: 分配并初始化工具栏对象后使用此选项:
toolbar.tintColor = [UIColor darkGrayColor];
Hope this helps you. 希望这对你有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.