知行合一,知是行之始,行是知之成,知而不行非真知,行而不知非真行!凡事应理论+实践!打破思维惯性和过度思考可能会带来的决策风险!
iOS Tabbar基本设置
iOS Tabbar基本设置

iOS Tabbar基本设置

1、修改tabbar高度

  • 重写- (void)viewWillLayoutSubviews方法
//改变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的文字大小和位置

  • 使用[UITabBarItem appearance]方法,需要注意的是:如果使用 viewcontroller.tarBarItem 设置,如[viewcontroller.tarBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:11]} forState:UIControlStateNormal];
    那么为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)];

}

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注