Color of UIToolbar not changing
Asked Answered
B

4

5

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?

Bobbyebobbysocks answered 7/4, 2011 at 13:12 Comment(0)
N
7

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

Nonappearance answered 7/4, 2011 at 13:58 Comment(3)
unfortunately it doeson't response to tintcolor eitherBobbyebobbysocks
tools = [[uitoolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 46.01f)];Bobbyebobbysocks
I just tried creating a new "view-based" application and added the (updated) code above to the viewController and it worked for me.Nonappearance
B
14

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...

Boarhound answered 13/1, 2014 at 5:19 Comment(0)
N
7

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

Nonappearance answered 7/4, 2011 at 13:58 Comment(3)
unfortunately it doeson't response to tintcolor eitherBobbyebobbysocks
tools = [[uitoolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 46.01f)];Bobbyebobbysocks
I just tried creating a new "view-based" application and added the (updated) code above to the viewController and it worked for me.Nonappearance
P
0

Use this after you allocate and initialize you toolbar object:

toolbar.tintColor = [UIColor darkGrayColor];

Hope this helps you.

Paulinapauline answered 7/4, 2011 at 14:9 Comment(0)
M
0

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
Mononuclear answered 28/4, 2017 at 8:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.