Discussion Forums  >  Status Bar, Navigation Bar

Replies: 11    Views: 406

leon7000
Lost but trying
Profile
Posts: 58
Reg: Mar 02, 2012
Saudi Arabia
6,080
02/16/13 07:21 AM (11 years ago)

Hi : simple way to change the tab bar and the navbar color and background

Hi Every Body and hope you have nice day .. i hope this will help some body here :-) if you want change the color or the lighting color after click the tabbar button or if you want change the background to the tabbar or navbar you only need to add on your "appDelegate" this code and change it to any thing you want : after: -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ add this : //code for change the color and background UITabBar *taBarAppearance = [UITabBar appearance]; [taBarAppearance setBackgroundImage:[UIImage imageNamed:@"tabbarbackground.png"]]; [taBarAppearance setSelectionIndicatorImage:[UIImage imageNamed:@"selecttabbarbackground.png"]]; [[UITabBar appearance] setSelectedImageTintColor:[UIColor blueColor]]; [[UITabBarItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor orangeColor], UITextAttributeTextColor, [UIFont systemFontOfSize:14.0f], UITextAttributeFont,nil] forState:UIControlStateHighlighted]; UIImage *navBarImage = [UIImage imageNamed:@"navbarbackground.png"]; [[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault]; UIImage *barButton = [[UIImage imageNamed:@"button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)]; [[UIBarButtonItem appearance] setBackgroundImage:barButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; UIImage *backButton = [[UIImage imageNamed:@"back-button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,15,0,6)]; [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; //end of code you can see example here : http://t.co/PK2yhi3r and i miss you all :)) Mohd
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
02/16/13 08:11 AM (11 years ago)
That stitched Navbar looks really nice :) Cheers! -- Smug
 
leon7000
Lost but trying
Profile
Posts: 58
Reg: Mar 02, 2012
Saudi Arabia
6,080
like
02/16/13 08:25 AM (11 years ago)
Hi Smug Yes it is and i like it same as wood nav too :) Thank you
 
Black White
I hate code!
Profile
Posts: 292
Reg: Feb 22, 2012
hanoi
4,770
like
02/16/13 09:21 AM (11 years ago)
Nice tip @Mohd, Thank you :)
 
leon7000
Lost but trying
Profile
Posts: 58
Reg: Mar 02, 2012
Saudi Arabia
6,080
like
02/16/13 10:09 AM (11 years ago)
You Are welcome BW :)
 
Cyrus_8888
I hate code!
Profile
Posts: 151
Reg: Dec 24, 2011
Sydney
1,610
like
02/16/13 05:29 PM (11 years ago)
Hi Mohd, Great Post! Any clue on the android version? Thank you
 
JimmySaver
Aspiring developer
Profile
Posts: 187
Reg: Apr 09, 2012
location unknow...
5,870
like
02/24/13 12:40 PM (11 years ago)
Hi Mohd, I love workarounds and therefore, love your posts! A question on this one... I only want to change the back button from the word "back" to an image. Would the code work for this? I think I would only put certain parts of your code into my appDelegate file to get this to work, am I right? If I am, which parts?!
 
Boliviapp
Veteran developer
Profile
Posts: 4
Reg: Jul 03, 2013
Cochabamba
40
like
07/09/13 03:14 PM (10 years ago)
Hi Mohd, Im new on this, i paste your code and change the image names, but i have a lot of errors in appDelegate.h, i have to make more changes? Thanks
 
mysps
Code is Art
Profile
Posts: 2082
Reg: May 14, 2011
Palma
33,320
like
07/09/13 03:41 PM (10 years ago)
there is a bracket missing from the original post. first line: [UITabBar *taBarAppearance = [UITabBar appearance]; [taBarAppearance setBackgroundImage:[UIImage imageNamed:@"tabbarbackground.png"]]; [taBarAppearance setSelectionIndicatorImage:[UIImage imageNamed:@"selecttabbarbackground.png"]]; [[UITabBar appearance] setSelectedImageTintColor:[UIColor blueColor]]; [[UITabBarItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:[UIColor orangeColor], UITextAttributeTextColor, [UIFont systemFontOfSize:14.0f], UITextAttributeFont,nil] forState:UIControlStateHighlighted]; UIImage *navBarImage = [UIImage imageNamed:@"navbarbackground.png"]; [[UINavigationBar appearance] setBackgroundImage:navBarImage forBarMetrics:UIBarMetricsDefault]; UIImage *barButton = [[UIImage imageNamed:@"button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)]; [[UIBarButtonItem appearance] setBackgroundImage:barButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; UIImage *backButton = [[UIImage imageNamed:@"back-button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0,15,0,6)]; [[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButton forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
 
Boliviapp
Veteran developer
Profile
Posts: 4
Reg: Jul 03, 2013
Cochabamba
40
like
07/10/13 02:22 PM (10 years ago)
Hi, thanks! I still have some errors like: "Use of undeclared identifier 'taBarAppearance' Thanks again
 
Boliviapp
Veteran developer
Profile
Posts: 4
Reg: Jul 03, 2013
Cochabamba
40
like
07/10/13 02:34 PM (10 years ago)
Hi, thanks! I still have some errors like: "Use of undeclared identifier 'taBarAppearance' Thanks again
 
farcat
buzztouch Evangelist
Profile
Posts: 1008
Reg: Jan 27, 2012
France
13,230
like
09/22/13 02:03 PM (10 years ago)
Hey, just in case somebody still follows this post: It was a great trick but doesn't work anymore on Xcode5 + IOS7. Looking for a substitute now. Farcat
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.