2017-06-12 205 views
0

我正在使用下面的代码来显示工具栏作为拾取器视图的附件视图。我想自定义工具栏的颜色。我不确定在下面的代码中有什么错误。有没有更好的方式来实现这一目标UIToolbar背景颜色不变

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]; 

由于提前

+0

的可能的复制[UIToolbar setBackgroundColor不充分变色](https://stackoverflow.com/questions/19401507/uitoolbar-setbackgroundcolor-doesnt-fully-change-color) –

回答

0

的Objective - C

你的代码是工作的罚款。 试图改变像下面

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]; 

state_closey位置,如果你想设置y = 0然后隐藏的导航栏。

[self.navigationController.navigationBar setHidden:true];