02百思不得姐设置TabBar
来源:互联网 发布:怎么看淘宝卖家的佣金 编辑:程序博客网 时间:2024/04/30 00:50
首先我们来分析下界面:
这是一典型的TabBarController,底部TabBar所拥有的元素有图片和文字,并且可以看到这个图片和文字有两种状态一种是默认灰色的,和一种点击状态的图片,
好了现在界面元素已经分析完了接下来就开始代码编写了!!!!!!
1>>首先我们删除项目中无用文件并且新建我们自己的TabBarController
2>>既然我们已经有了这个TabBarController那我们就把它设置成根控制器那么我们在AppDelegate设置下
/*当程序启动执行完毕时会调用此方法/
- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions {
// Override point for customization after application launch.
//创建窗口
self.window = [[UIWindow alloc]init];
self.window.frame = [UIScreen mainScreen].bounds;
//设置窗口的根控制器
self.window.rootViewController = [[GCSTabBarController alloc]init];
//显示窗口
[self.window makeKeyAndVisible];
return YES;
}
NOTE:
这里需要注意的就是当你实例化一个window窗口是一定要设置他的大小否则是不会显示的并且设置为可显示状态,最好试验下哈!!!!绝知此事要躬行
3>>既然这个根控制器已经设置好了,那该里面的东西了也!我们回到自己的TabBarController
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. NSMutableDictionary *attrs = [NSMutableDictionary dictionary]; attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12]; attrs[NSForegroundColorAttributeName] = [UIColor grayColor]; NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary]; selectedAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12]; selectedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor]; //添加子控制器 UIViewController *vc01 = [[UIViewController alloc]init]; vc01.tabBarItem.title = @"精华"; vc01.tabBarItem.image = [UIImage imageNamed:@"tabBar_essence_icon"]; vc01.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_essence_click_icon"]; vc01.view.backgroundColor = [UIColor redColor]; [vc01.tabBarItem setTitleTextAttributes:attrs forState:UIControlStateNormal]; [vc01.tabBarItem setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected]; [self addChildViewController:vc01]; UIViewController *vc02 = [[UIViewController alloc]init]; vc02.tabBarItem.title=@"新帖"; vc02.tabBarItem.image = [UIImage imageNamed:@"tabBar_new_icon"]; vc02.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_new_click_icon"]; vc02.view.backgroundColor = [UIColor blackColor]; [vc02.tabBarItem setTitleTextAttributes:attrs forState:UIControlStateNormal]; [vc02.tabBarItem setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected]; [self addChildViewController:vc02]; UIViewController *vc03 = [[UIViewController alloc]init]; vc03.tabBarItem.title = @"关注"; vc03.tabBarItem.image = [UIImage imageNamed:@"tabBar_friendTrends_icon"]; vc03.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_friendTrends_click_icon"]; vc03.view.backgroundColor = [UIColor yellowColor]; [vc03.tabBarItem setTitleTextAttributes:attrs forState:UIControlStateNormal]; [vc03.tabBarItem setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected]; [self addChildViewController:vc03]; UIViewController *vc04 = [[UIViewController alloc]init]; vc04.tabBarItem.title = @"我"; vc04.tabBarItem.image = [UIImage imageNamed:@"tabBar_me_icon"]; vc04.tabBarItem.selectedImage = [UIImage imageNamed:@"tabBar_me_click_icon"]; vc04.view.backgroundColor = [UIColor greenColor]; //设置字体的默认和点击两种状态的颜色 [vc04.tabBarItem setTitleTextAttributes:attrs forState:UIControlStateNormal];// [vc04.tabBarItem setTitleTextAttributes:attrs forState:UIControlStateSelected]; [self addChildViewController:vc04];}
这个方法是在视图加载完之后调用的!我们向TabBarController添加四个自控制器,就像之前我们说的一样这个底部导航有两种状态一种是默认的状态一种是点击后的状态,我们可以看到字体设置是通过字典去给“装饰”的
代码下载地址 http://download.csdn.net/detail/u014360817/9459812
0 0
- 02百思不得姐设置TabBar
- 百思不得姐自定义TabBar
- 不得姐实战教程 02 配置tabbar
- 自定义tabBar(仿百思不得姐的tabBar设计)
- 《百思不得姐》
- 百思不得姐
- 百思学习笔记02-设置tabbar
- 02-百思不得姐(第二天)
- 百思不得姐项目学习总结
- 03-百思不得姐(第三天)
- 04-百思不得姐(第四天)
- 03百思不得姐appearance使用
- 百思不得姐框架(一)
- 06-百思不得姐(第六天)
- 百思不得姐框架(二)
- 07-百思不得姐(第七天)
- 09-百思不得姐(第九天)
- iOS 高仿《百思不得姐》
- 求四个数的最大公约数
- UVa 1584 - Circular Sequence
- Spring Ioc set注入
- 利用HttpClient发送Get和Post请求
- QT版DomainName软件导出BUG
- 02百思不得姐设置TabBar
- 总结三
- springMVC的简单配置
- unity3d的playmaker插件使用教程,三、对象出入触发,声音播放
- pandas处理数据例子
- QTP 导入 XML作为环境变量
- Xcode 7.3编译的cocos2d-x程序崩溃问题
- HDOJ 2050 折线分割平面
- hbase和hive的集合