百思学习笔记03-appearance

来源:互联网 发布:java se到底是什么 编辑:程序博客网 时间:2024/05/16 11:38

用appearance来精简代码

// 通过appearance统一设置所有UITabBarItem的文字属性    // 后面带有UI_APPEARANCE_SELECTOR的方法, 都可以通过appearance对象来统一设置    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];        NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];    selectedAttrs[NSFontAttributeName] = attrs[NSFontAttributeName];    selectedAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];        UITabBarItem *item = [UITabBarItem appearance];    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];        // 添加子控制器    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];    [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 grayColor];    [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 greenColor];    [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 blueColor];    [self addChildViewController:vc04];


0 0
原创粉丝点击