UITabBarController使用得非常广泛,说说它的核心,UITabBar的使用。
建一个工程,创建4个UIViewController用来作切换的视图控制器,为了方便,就在AppDelegate.m文件里面写代码,如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
FirstViewController *fvc = [[FirstViewController alloc]init];
UINavigationController *fNav = [[UINavigationController alloc]initWithRootViewController:fvc];
SecondViewController *svc = [[SecondViewController alloc]init];
UINavigationController *sNav = [[UINavigationController alloc]initWithRootViewController:svc];
ThirdViewController *tvc = [[ThirdViewController alloc]init];
UINavigationController *tNav = [[UINavigationController alloc]initWithRootViewController:tvc];
FourthViewController *fourVc = [[FourthViewController alloc]init];
UINavigationController *fourNav = [[UINavigationController alloc]initWithRootViewController:fourVc];
UITabBarController *tab = [[UITabBarController alloc]init];
tab.viewControllers = @[fNav,sNav,tNav,fourNav];
self.window.rootViewController = tab;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
FirstViewController、SecondViewController、ThirdViewController、FourthViewController是UITabBarController的4个

本文详细介绍了在iOS开发中如何使用UITabBar,包括创建UIViewController子类作为标签控制器,设置背景色,添加icon和文字,以及自定义选中颜色和使用自定义图片。通过实例代码展示了如何在AppDelegate.m中配置UITabBarController,以及UITabBarItem的图标和文字设置技巧。
最低0.47元/天 解锁文章
428

被折叠的 条评论
为什么被折叠?



