0

I am using the below code to display a toolbar as a accessory view for a picker view. I want to customise the tool bar colour. I am not sure whats wrong in this below code. Is there a better way to achieve this

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

Thanks in Advance

AJ Sanjay
  • 1,276
  • 1
  • 12
  • 29
  • Possible duplicate of [UIToolbar setBackgroundColor doesn't fully change color](https://stackoverflow.com/questions/19401507/uitoolbar-setbackgroundcolor-doesnt-fully-change-color) – Zღk Jun 12 '17 at 07:59

1 Answers1

0

Objective - C

Your code is working fine. try to change y position of the state_close like below

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

if you want to set y = 0 then hide navigationBar.

[self.navigationController.navigationBar setHidden:true];
Community
  • 1
  • 1
Hitesh
  • 896
  • 1
  • 9
  • 22