In my navigation bar, I have a pair of rightBarButtonItems that have custom icons (the icon images are white, which works well with the iOS 6 base color scheme).
In iOS 7, loading images using initWithTitle (see code snippet 1) replaces the βwhiteβ color in the icon with the corresponding global hue (in this case, the specific color is blue)
Code Snippet 1 :
UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:(UIBarButtonItemStyle) UIBarButtonSystemItemCancel target:(self) action:@selector(refreshList)]; refreshButton.image = [UIImage imageNamed:@"RefreshIcon.png"];
However, I needed to use initWithCustomView to overcome strange changes in behavior that caused the icons to get out of sight. The main idea was to set the size of the icons. initWithCustomView solved the calibration problem, but does not display button images with a global hue, they are displayed in the image color (white). Code Snippet 2 shows how I create a button with initWithCustomView.
Code Snippet 2 :
CGRect frameCustomButton2 = CGRectMake(0.0, 0.0, 18.0, 18.0); UIButton *customButton2 = [[UIButton alloc] initWithFrame:frameCustomButton2]; [customButton2 setBackgroundImage:iconRefreshButton forState:UIControlStateNormal]; UIBarButtonItem *barCustomButton2 =[[UIBarButtonItem alloc] initWithCustomView:customButton2 ]; barCustomButton2.image = iconRefreshButton; [customButton2 addTarget:self action:@selector(refreshList) forControlEvents:UIControlEventTouchUpInside];
All this code, of course, is in the (void) viewDidLoad. I tried things like:
barCustomButton2.tintColor = [UIColor blackColor];
or [barButtonAppearance setTintColor: [UIColor blackColor]]; // does not work
and they do not override the white color of the image. Does this look like creating a custom view after viewing in global hue color?
How can I make sure the button icon is global?
Thanks!
ios objective-c iphone ios7 uibuttonbaritem
Jmc
source share