iphone - Setting UITabBarIcon tint when unselected -
i trying set icons of uitabbaritem, not working. way, i'm using xcode 5 beta project.
@implementation appdelegate - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions { { [[uitabbaritem appearance] settitletextattributes:[nsdictionary dictionarywithobjectsandkeys:[uicolor whitecolor], nsforegroundcolorattributename, nil] forstate:uicontrolstatenormal]; uiimage *tabbarbackground = [uiimage imagenamed:@"tabbar.png"]; [[uitabbar appearance] setbackgroundimage:tabbarbackground]; [[uitabbar appearance] setselectionindicatorimage:[uiimage imagenamed:@"tabbar_selected.png"]]; [[uitabbar appearance] settintcolor:[uicolor whitecolor]]; } return yes; }
i trying icons white when both selected , unselected, remaining gray in unselected state.
edit
i tried doing this, im getting error "expression result unused"
uitabbarcontroller *tabbarcontroller = (uitabbarcontroller *)self.window.rootviewcontroller; uitabbar *tabbar = tabbarcontroller.tabbar; uitabbaritem *tabbaritem1 = [tabbar.items objectatindex:0]; tabbaritem1.title = @"home"; uiimage *graph = [uiimage imagenamed:@"graph.png"]; [tabbaritem1 initwithtitle:(nsstring *)@"hello" image:(uiimage *)graph selectedimage:(uiimage *)graph];
tintcolor
sets tint color of background, can't see if use custom background image. if don't want have system default gradient have use setfinishedselectedimage:withfinishedunselectedimage:
, set white image both of them.
like this:
uiimage *selectedimage = ... uiimage *unselectedimage = selectedimage; [tabbaritem setfinishedselectedimage:selectedimage withfinishedunselectedimage:unselectedimage];
if setting images in storyboard can iterate on existing uitabbaritems , change images.
put application:didfinishlaunchingwithoptions:
uitabbarcontroller *tabbarcontroller = (uitabbarcontroller *)self.window.rootviewcontroller; nsassert([tabbarcontroller iskindofclass:[uitabbarcontroller class]], @"self.window.rootviewcontroller must tabbarcontroller"); (uiviewcontroller *viewcontroller in tabbarcontroller.viewcontrollers) { uitabbaritem *tabbaritem = viewcontroller.tabbaritem; uiimage *tabimage = tabbaritem.image; [tabbaritem setfinishedselectedimage:tabimage withfinishedunselectedimage:tabimage]; }
Comments
Post a Comment