UIToolbar shows different color on ios 5.0 and ios 6.0 Simulators

99封情书 提交于 2019-12-13 04:10:11

问题


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

回答1:


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.




回答2:


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




回答3:


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?




回答4:


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



回答5:


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


来源:https://stackoverflow.com/questions/14098743/uitoolbar-shows-different-color-on-ios-5-0-and-ios-6-0-simulators

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!