Skip to content

Instantly share code, notes, and snippets.

@lamprosg
Last active December 16, 2015 02:19
Show Gist options
  • Select an option

  • Save lamprosg/5361109 to your computer and use it in GitHub Desktop.

Select an option

Save lamprosg/5361109 to your computer and use it in GitHub Desktop.
(iOS) Navigation & Tabbar controllers
- (void)customizeAppearance {
// customize the navigation bar
[[UINavigationBar appearance] setTitleTextAttributes:@{UITextAttributeFont : kNavigationBarTitleFont}];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
// UIBarButtonItem
UIImage *button = [[UIImage imageNamed:@"button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UIBarButtonItem appearance] setBackgroundImage:button forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setTitleTextAttributes:@{UITextAttributeFont:[UIFont fontWithName:@"Verdana" size:0.0]} forState:UIControlStateNormal];
// Back Button
UIImage *buttonBack = [[UIImage imageNamed:@"button_back.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
// customize the tab bar
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabbar.png"]];
// customize the labels
//[[UILabel appearance] setTextColor:[UIColor redColor]];
[[UILabel appearance] setFont:[UIFont fontWithName:@"Verdana" size:18.0]];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self customizeAppearance];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:ASSET_BY_SCREEN_HEIGHT(@"main_bg")]];
// Override point for customization after application launch.
HomeViewController *homeCtrl = [[HomeViewController alloc] init];
UINavigationController *homeNavCtrl = [[UINavigationController alloc] initWithRootViewController:homeCtrl];
[homeNavCtrl setNavigationBarHidden:YES animated:NO];
// init search controller
SearchViewController *searchCtrl = [[SearchViewController alloc] init];
UINavigationController *searchNavCtrl = [[UINavigationController alloc] initWithRootViewController:searchCtrl];
// init profile controller
ProfileViewController *profileCtrl = [[ProfileViewController alloc] init];
UINavigationController *profileNavCtrl = [[UINavigationController alloc] initWithRootViewController:profileCtrl];
// init buy controller
BuyViewController *buyCtrl = [[BuyViewController alloc] init];
UINavigationController *buyNavCtrl = [[UINavigationController alloc] initWithRootViewController:buyCtrl];
// init sell controller
SellViewController *sellCtrl = [[SellViewController alloc] init];
UINavigationController *sellNavCtrl = [[UINavigationController alloc] initWithRootViewController:sellCtrl];
self.tabBarController = [[UITabBarController alloc] init];
NSArray* controllers = [NSArray arrayWithObjects:homeNavCtrl, searchNavCtrl, sellNavCtrl, buyNavCtrl, profileNavCtrl, nil];
self.tabBarController.viewControllers = controllers;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment