iOS Tabbar基本设置

2019-04-12  本文已影响0人  Cingjin

1、修改tabbar高度

//改变tabbar高度
- (void)viewWillLayoutSubviews{
    CGRect tabFrame = self.tabBar.frame;
    tabFrame.size.height = 49;
    tabFrame.origin.y = self.view.frame.size.height - 49;
    self.tabBar.frame = tabFrame;
}

2、修改TabBarItem的文字大小和位置

+ (void)initialize {
    
    // 通过appearance统一设置所有UITabBarItem的文字属性
    // 后面带有UI_APPEARANCE_SELECTOR的方法,都可以通过appearance对象来统一设置
    // 正常情况下的属性
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSFontAttributeName] = [UIFont systemFontOfSize:10];
    attrs[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"#666666"];
    
    // 选中情况下的属性
    NSMutableDictionary *attrsSelected = [NSMutableDictionary dictionary];
    attrsSelected[NSFontAttributeName] = attrs[NSFontAttributeName]; 
    attrsSelected[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"#28D769"];
    UITabBarItem *item = [UITabBarItem appearance];
    
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:attrsSelected forState:UIControlStateSelected];
    
    [UITabBar appearance].translucent = NO;
    [[UITabBar appearance]setBackgroundImage:WTVImage(@"icon_tabbarImage")];
    
    //设置title的位置
    [[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -3)];
    
}
上一篇下一篇

猜你喜欢

热点阅读