0

I have set tintcolor for my UIToolBar.It displays Correctly in ios 6.0 but it shows black color on ios 5.0 simulator. My code is here

originalBounds = mysearchBarBarItem.customView.bounds;
mySearchBar.bounds = CGRectMake(0,0,215,44);
myTopToolbar.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:NAVIGATION_BAR_BACKGROUND]];
myTopToolbar.barStyle = UIBarStyleDefault;

mySearchBar.barStyle = UIBarStyleDefault;
mySearchBar.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:NAVIGATION_BAR_BACKGROUND]];

[myTopToolbar setItems:toolBarItemsArray animated:YES];
Prince Kumar Sharma
  • 12,591
  • 4
  • 59
  • 90
Harikrishnan
  • 9,688
  • 11
  • 84
  • 127

5 Answers5

2

I don't know if this can make a difference, but you could try to change the order in which you assign the style and color of the bar. Try:

myTopToolbar.barStyle = UIBarStyleDefault;   
myTopToolbar.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:NAVIGATION_BAR_BACKGROUND]];

It's possible that assigning the style after changing the tintcolor resets the color.

EDIT

Why this would affect only ios5 and not ios6 I don't know.

The dude
  • 7,896
  • 1
  • 25
  • 50
2

You can use UIAppearance (for iOS 5.0 and above) .

Nikita P
  • 4,226
  • 5
  • 31
  • 55
1

Try to set color property

myTopToolbar.tintColor = [UIColor redColor]; 

If this works fine in both iOS6 and iOS5, then problem should be in image.

Edited Check this question

iphone:UIToolbar when set to tint color behaves differently on iOS 5 and ios6 simulator?

Community
  • 1
  • 1
thavasidurai
  • 1,972
  • 1
  • 26
  • 51
1

Try to do this in your app delegate implementation class this will change the toolBar and searchBar color throughout the application

for setting tint of searchbar

[[UISearchBar appearance] setTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:NAVIGATION_BAR_BACKGROUND]]];

OR

[[UISearchBar appearance] setTintColor:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1]];

for setting tint of toolbar

[[UIToolbar appearance] setTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:NAVIGATION_BAR_BACKGROUND]];

OR

[[UIToolbar appearance] setTintColor:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1]];

for setting background image

[[UIToolbar appearance] setBackgroundImage:[UIImage imageNamed:@"bgtoolbar.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
Talha
  • 809
  • 4
  • 13
  • 1
    That's strange please try this [[UISearchBar appearance] setTintColor:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1]]; and [[UIToolbar appearance] setTintColor:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1]]; – Talha Dec 31 '12 at 08:59
  • That worked. Got a very light Black color. But It has changed the color of toolbars in entire application. – Harikrishnan Dec 31 '12 at 09:11
  • yes that will change tollbar color throughout the application if you use it in app delegate, if you want specific toolbar in any viewController to change then do it in your that viewController – Talha Dec 31 '12 at 10:38
0

I have solveed It. just converted the Image to RGB Values and set like this.

myTopToolbar.tintColor = [UIColor colorWithRed:139/256.0 green:0/256.0 blue:0/256.0 alpha:1.0];
Harikrishnan
  • 9,688
  • 11
  • 84
  • 127