//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;
iOS 設置UITabBarItem
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發上,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側響起,我...
推薦閱讀更多精彩內容
- -(void)setTabBarItem:(UITabBarItem*)tabbarItem Title:(NSS...
- 1.改變UITabBarItem 字體顏色 [[UITabBarItemappearance]setTitleTe...
- iOS13碰到設置tabbar字體為選中狀態顏色,正常切換沒有問題,push后再返回,選中顏色變化系統藍色目前碰到...
- iOS13碰到設置tabbar字體為選中狀態顏色,正常切換沒有問題,push后再返回,選中顏色變化系統藍色解決方法...
- 使用新版XcodeVersion 11.2.1 (11B500)創建項目時,發現對UITabController的...