iphone - Cannot change UIBarButtonItem color attribute in disabled state -
i have created uitoolbar 3 bar button items. works when using default font , font size. however, font bit large , want resize it. used following code customize font size , color in normal state, when, say, button #1 disabled text color remains black both enabled , disabled states - i.e. doesn't change color gray.
nsdictionary *ena = @{nsfontattributename:[uifont fontwithname:@"helvetica" size:12.0], nsforegroundcolorattributename: [uicolor blackcolor]}; nsdictionary *dis = @{nsfontattributename:[uifont fontwithname:@"helvetica" size:12.0], nsforegroundcolorattributename: [uicolor graycolor]}; [[uibarbuttonitem appearance] settitletextattributes:ena forstate:uicontrolstatenormal]; [[uibarbuttonitem appearance] settitletextattributes:dis forstate:uicontrolstatedisabled];
i'd appreciate feedback on went wrong above code.
create outlet barbuttonitem; suppose mybarbutton. disable storyboard. call in viewdidload()
if (mybarbutton.enabled == 'no') { nsdictionary *dis = @{nsfontattributename:[uifont fontwithname:@"helvetica" size:12.0], nsforegroundcolorattributename: [uicolor graycolor]}; [[uibarbuttonitem appearance] settitletextattributes:ena forstate:uicontrolstatenormal]; }
then after doing job when necessary enable mybarbutton, run code below
nsdictionary *dis = @{nsfontattributename:[uifont fontwithname:@"helvetica" size:12.0], nsforegroundcolorattributename: [uicolor blackcolor]}; [[uibarbuttonitem appearance] settitletextattributes:ena forstate:uicontrolstatenormal];
actually, uicontrolstatedisabled not working observed.
Comments
Post a Comment