iOS 设置UITabBarItem

    //tabbar item在各个样式的下的布局
    
    //上下结构tabbar item布局
    UITabBarItemAppearance *stack_apperance = [[UITabBarItemAppearance alloc] initWithStyle:UITabBarItemAppearanceStyleStacked];
    stack_apperance.normal.titlePositionAdjustment = UIOffsetMake(0, 1);
    stack_apperance.selected.titlePositionAdjustment = UIOffsetMake(0, 1);
    stack_apperance.normal.titleTextAttributes = @{NSForegroundColorAttributeName: color, NSFontAttributeName:UIFont.bb_12};
    stack_apperance.selected.titleTextAttributes = @{NSForegroundColorAttributeName: scolor, NSFontAttributeName:UIFont.bb_12};
    
    //左右结构tabbar item布局(左右结构时字体一定要比上下布局小,否则会由于间隔问题导致文字显示不全)
    UITabBarItemAppearance *inline_apperance = [[UITabBarItemAppearance alloc] initWithStyle:UITabBarItemAppearanceStyleInline];
    inline_apperance.normal.titleTextAttributes = @{NSForegroundColorAttributeName: color, NSFontAttributeName:UIFont.bb_10};
    inline_apperance.selected.titleTextAttributes = @{NSForegroundColorAttributeName: scolor, NSFontAttributeName:UIFont.bb_10};
    
    //左右结构被挤压时的tabbar item布局(某些特殊情况,只会出现在ipad上,比如多屏侧边栏出现时会压缩app的宽度)
    UITabBarItemAppearance *compact_apperance = [[UITabBarItemAppearance alloc] initWithStyle:UITabBarItemAppearanceStyleCompactInline];
    compact_apperance.normal.titleTextAttributes = @{NSForegroundColorAttributeName: color, NSFontAttributeName:UIFont.bb_7};
    compact_apperance.selected.titleTextAttributes = @{NSForegroundColorAttributeName: scolor, NSFontAttributeName:UIFont.bb_7};
    

    //tabbar item样式类
    UITabBarAppearance *bar_a = [UITabBarAppearance new];
    bar_a.stackedLayoutAppearance = stack_apperance;
    bar_a.inlineLayoutAppearance = inline_apperance;
    bar_a.compactInlineLayoutAppearance = compact_apperance;
    
    //tabbar item
    UITabBarItem *tab = [[UITabBarItem alloc] initWithTitle:title image:icon selectedImage:sicon];
    tab.imageInsets = UIEdgeInsetsZero;
    tab.standardAppearance = bar_a;
    tab.scrollEdgeAppearance = bar_a;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容