ios - Selection Indicator of tab bar not working -


hi newbie ios.

i have implemented tabbarcontroller along 4 tabbar items through storyboard. now, need customise tab bar shown in image below. have set background tab bar.

 + (uiimage *)imagefromcolor:(uicolor *)color {      cgrect rect = cgrectmake(0, 0, 1, 1);      uigraphicsbeginimagecontext(rect.size);      cgcontextref context = uigraphicsgetcurrentcontext();      cgcontextsetfillcolorwithcolor(context, [color cgcolor]);      cgcontextfillrect(context, rect);      uiimage *image = uigraphicsgetimagefromcurrentimagecontext();      uigraphicsendimagecontext();      return image;  }    - (bool)application:(uiapplication *)application didfinishlaunchingwithoptions:(nsdictionary *)launchoptions {        [[uitabbar appearance] settintcolor:[uicolor whitecolor]];        [[uitabbar appearance] setbackgroundimage:[appdelegate imagefromcolor:[uicolor blackcolor]]];        return yes;    } 

the background tab bar set without problems.

when try set colour selected tab bar item, not work. don't know why?

[[uitabbar appearance]setselectionindicatorimage:[appdelegate imagefromcolor:[uicolor orangecolor]]]; 

i need customise tab bar this:

enter image description here

how can it?

firstly should remember configuration of uitabbar should done in appdelegate.m:

you should add [[uitabbar appearance]setselectionindicatorimage:[appdelegate imagefromcolor:[uicolor orangecolor]]]; in appdelegate.m in applicationdidfinishlaunchingwithoptions method.

secondly in you're case should provide tab bar item selected state example:

   uitabbarcontroller *tabbarcontroller = (uitabbarcontroller   *)self.window.rootviewcontroller;    uitabbar *tabbar = tabbarcontroller.tabbar;    uitabbaritem *tabbaritem1 = [tabbar.items objectatindex:0];     //we set title    tabbaritem1.title = @"home";     //we set highlighted state    [tabbaritem1 setfinishedselectedimage:[uiimage imagenamed:@"home_selected.png"] withfinishedunselectedimage:[uiimage imagenamed:@"home.png"]];     // change tab bar background    uiimage* tabbarbackground = [uiimage imagenamed:@"tabbar.png"];    [[uitabbar appearance] setbackgroundimage:tabbarbackground];    // tab bar active background    [[uitabbar appearance] setselectionindicatorimage:[uiimage imagenamed:@"tabbar_selected.png"]]; 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -