UI基础篇-UITabbarController

1.创建UITabbarController

- (instancetype)initWithTitle:(NSString*)title image:(UIImage *)image selectedImage:
(UIImage *)selectedImage NS_AVAILABLE_IOS(7_0)
'添加自控制器'
childVC.title = title;
childVC.tabBarItem.image = [UIImage imageWithName:imgName];
childVC.tabBarItem.selectedImage = [UIImage imageWithName:selectedImageName];
DCNavigationController *nav = [[DCNavigationController alloc]initWithRootViewController:childVC];
[self addChildViewController:nav];

2.设置tabbar的文字属性

+(void)initialize //当第一次使用这个类的时候调用,并且只执行一次
{
    //设置tabBarItem 的文字属性
    UITabBarItem *appearance = [UITabBarItem appearance];
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = [UIColor orangeColor];
    [appearance setTitleTextAttributes:dict forState:UIControlStateSelected];
}

3.UITabBarItem

//创建系统自带的UITabBarSystemItem
- (instancetype) initWithTabBarSystemItem: (UITabBarSystemItem)systemItem tag:(NSInteger)tag
//设置UITabBarItem徽标
@property(nonatomic,copy) NSString *badgeValue
//移动标题
[childVc.tabBarItem setTitlePositionAdjustment:UIOffsetMake(0, -4)];

你可能感兴趣的:(UI基础篇-UITabbarController)