UI基礎 UITabBarController
阿新 • • 發佈:2020-08-09
app.m
#import "AppDelegate.h" #import "TmailViewController.h" #import "TaoBaoViewController.h" @interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];// Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; //淘寶頁面 TaoBaoViewController *taobao =[[TaoBaoViewController alloc] init]; UINavigationController *taoNav=[[UINavigationController alloc] initWithRootViewController:taobao];//設定標題 taoNav.tabBarItem.title=@"淘寶"; //設定未選中的圖片 taoNav.tabBarItem.image=[UIImage imageNamed:@"taobao"]; //設定選中時的圖片 taoNav.tabBarItem.selectedImage=[UIImage imageNamed:@"taobao"]; //天貓頁面 TmailViewController *tmall =[[TmailViewController alloc] init]; UINavigationController*tmallNav=[[UINavigationController alloc]initWithRootViewController:tmall]; //設定標題 tmallNav.tabBarItem.title=@"天貓"; //設定未選中的圖片 tmallNav.tabBarItem.image=[UIImage imageNamed:@"tianmao"]; //設定選中時的圖片 tmallNav.tabBarItem.selectedImage=[UIImage imageNamed:@"tianmao"]; //統一設定導航欄的格式 [[UINavigationBar appearance] setBarTintColor:[UIColor greenColor]]; [[UINavigationBar appearance] setTranslucent:NO]; UITabBarController *tabbarC =[[UITabBarController alloc]init]; // 將頁面放在tabbarcontroller 中 tabbarC.viewControllers= [NSArray arrayWithObjects:taoNav,tmallNav,nil]; //把tabbarcontroller 作為window的根檢視 self.window.rootViewController =tabbarC; return YES; }
taobao.m
#import "TaoBaoViewController.h" @interface TaoBaoViewController () @end @implementation TaoBaoViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor=[UIColor blueColor]; self.navigationItem.title=@"淘寶"; } @end
tmail.m
#import "TmailViewController.h" @interface TmailViewController () @end @implementation TmailViewController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor=[UIColor yellowColor]; self.navigationItem.title=@"天貓"; } @end