ios - Wrong barButton item tint for play/pause buttons built programatically -


i have uitoolbar audio controls. sometime around ios 7 upgrade color of bar changed , ios started shading buttons differently. introduced bug play , pause buttons change programatically don't match new of toolbar:

toolbar starts out looking fine:

toolbar starts out looking fine

now pressed play code inserted pause button wrong color:

now pressed play code inserted pause button wrong color

now pressed pause , code inserted play button, again wrong color:

now pressed pause , code inserted play button, again wrong color

i want play , pause buttons have same dark other buttons. assume have differently when building replacement buttons. raw icon images lighter color, ios toolbar seems automatically recoloring darker color storyboard, seen in first screenshot.

here's code use build buttons:

- (uibarbuttonitem *) makebarbutton: (nsstring *) imagename action:(sel)targetaction {     uiimage* image = [uiimage imagenamed:imagename];     cgrect frame = cgrectmake(0 - 20, 0 - 20, image.size.width + 20, image.size.height + 20);     uibutton *button = [[uibutton alloc] initwithframe:frame];     [button addtarget:self action:targetaction forcontrolevents:uicontroleventtouchupinside];     [button setimage:image forstate:uicontrolstatenormal];     [button setshowstouchwhenhighlighted:yes];     return [[uibarbuttonitem alloc] initwithcustomview:button]; }  - (void) setasplaying:(bool)isplaying {     self.rootviewcontroller.playing = isplaying;      // need change of play/pause buttons showing, if 1     // reverse current action isn't showing     if ((isplaying && !self.pausebutton) || (!isplaying && !self.playbutton))     {         uibarbuttonitem *buttontoremove = nil;         uibarbuttonitem *buttontoadd = nil;         if (isplaying)         {             buttontoremove = self.playbutton;             self.playbutton = nil;             self.pausebutton = [self makebarbutton:@"icon_pause.png" action:@selector(pauseaudio:)];             buttontoadd = self.pausebutton;         }         else         {             buttontoremove = self.pausebutton;             self.pausebutton = nil;             self.playbutton = [self makebarbutton:@"icon_play.png" action:@selector(playaudio:)];             buttontoadd = self.playbutton;         }          // reference current toolbar buttons         nsmutablearray *toolbarbuttons = [[self.toolbar items] mutablecopy];          // remove button toolbar , add other 1         if (buttontoremove)             [toolbarbuttons removeobject:buttontoremove];         if (![toolbarbuttons containsobject:buttontoadd])             [toolbarbuttons insertobject:buttontoadd atindex:4];          [self.toolbar setitems:toolbarbuttons];     } } 

appreciate this.

check following:

if images stored inside image assets, make sure template images.

then can either a) set tint colour in interface builder grey colour prefer or b) programmatically in makebarbutton method such;

button.tintcolor = [uicolor graycolor]; 

Comments