Ios UIToolbar背景色未更改

Ios UIToolbar背景色未更改,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,我使用下面的代码将工具栏显示为选择器视图的附件视图。我想定制工具栏的颜色。我不确定下面的代码有什么问题。有没有更好的方法来实现这一点 UIToolbar* state_close = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)]; state_close.translucent =NO; //.barStyle = UIBarStyleDefault; state_close.b

我使用下面的代码将工具栏显示为选择器视图的附件视图。我想定制工具栏的颜色。我不确定下面的代码有什么问题。有没有更好的方法来实现这一点

UIToolbar* state_close = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
state_close.translucent =NO; //.barStyle = UIBarStyleDefault;
state_close.barTintColor = [UIColor colorWithRed:0.94 green:0.94 blue:0.94 alpha:1.0];
[state_close sizeToFit];
提前感谢

目标-C 你的代码运行良好。 尝试更改
y
状态的位置\u close如下

UIToolbar *state_close = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 200, self.view.frame.size.width, 50)];
state_close.barTintColor = [UIColor blackColor];
state_close.alpha = 1.0;
[state_close sizeToFit];
[self.view addSubview:state_close];
如果要设置
y=0
,请隐藏导航栏

[self.navigationController.navigationBar setHidden:true];
可能重复的