UIToolbar shows different color on ios 5.0 and ios

2019-09-05 01:43发布

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

5条回答
乱世女痞
2楼-- · 2019-09-05 02:09

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.

查看更多
时光不老,我们不散
3楼-- · 2019-09-05 02:10

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];
查看更多
对你真心纯属浪费
4楼-- · 2019-09-05 02:15

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

查看更多
趁早两清
5楼-- · 2019-09-05 02:31

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?

查看更多
ら.Afraid
6楼-- · 2019-09-05 02:32

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];
查看更多
登录 后发表回答