當我設定 UITabBar 的外觀時,它使它成為 UITabBarItemimageInsets并且titlePositionAdjustment在 iOS 15 上不再受尊重。洗掉該[UITabBar appearance].standardAppearance = tabBarAppearance;行使其成為影像和標簽陣容,但無法設定背景顏色。有沒有人遇到過這樣的事情并解決了它?
代碼:
UITabBarAppearance *tabBarAppearance = [[UITabBarAppearance alloc] init];
[tabBarAppearance configureWithOpaqueBackground];
[UITabBar appearance].standardAppearance = tabBarAppearance;
[UITabBar appearance].scrollEdgeAppearance = tabBarAppearance;
static let tabBarImageInsets: UIEdgeInsets = UIEdgeInsets(top: 4.0, left: 0, bottom: -4.0, right: 0)
static let titlePositionAdjustmentValue: UIOffset = UIOffset(horizontal: 0.0, vertical: -8.0)
tabBarItem.imageInsets = tabBarImageInsets
tabBarItem.titlePositionAdjustment = titlePositionAdjustmentValue
圖片:
帶有外觀和未對齊標簽的標簽欄
沒有外觀的標簽欄,標簽和影像正確對齊,沒有背景
uj5u.com熱心網友回復:
我在實際閱讀 Apple 檔案后解決了這個問題:
if (@available(iOS 15.0, *)) {
UINavigationBarAppearance *navBarAppearance = [[UINavigationBarAppearance alloc] init];
[navBarAppearance configureWithOpaqueBackground];
[UINavigationBar appearance].standardAppearance = navBarAppearance;
[UINavigationBar appearance].compactAppearance = navBarAppearance;
[UINavigationBar appearance].scrollEdgeAppearance = navBarAppearance;
UITabBarAppearance *tabBarAppearance = [[UITabBarAppearance alloc] init];
[tabBarAppearance configureWithOpaqueBackground];
[UITabBar appearance].standardAppearance = tabBarAppearance;
[UITabBar appearance].scrollEdgeAppearance = tabBarAppearance;
UITabBarItemAppearance *tabBarItemAppearance = [[UITabBarItemAppearance alloc] init];
tabBarItemAppearance.normal.titleTextAttributes = [[RRUIDesignToken.font nav] makeTextAttributes];
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
tabBarItemAppearance.normal.titlePositionAdjustment = UIOffsetMake(0.0, -[RRUIDesignToken.size paddingXsmall]);
} else {
tabBarItemAppearance.normal.titlePositionAdjustment = UIOffsetMake(0.0, -[RRUIDesignToken.size paddingXxsmall]);
}
tabBarAppearance.stackedLayoutAppearance = tabBarItemAppearance;
tabBarAppearance.compactInlineLayoutAppearance = tabBarItemAppearance;
tabBarAppearance.inlineLayoutAppearance = tabBarItemAppearance;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/396663.html
下一篇:根據不同的列計算運行總計摘要
