【问题标题】:UITabBar items title position issueUITabBar 项目标题位置问题
【发布时间】:2021-10-10 17:37:52
【问题描述】:
我无法解决这个问题,与UITabBar 中每个标签栏项目的标题位置有关。我试过这个:
extension UITabBar {
override open var traitCollection: UITraitCollection {
if UIDevice.current.userInterfaceIdiom == .pad {
return UITraitCollection(horizontalSizeClass: .compact)
}
return super.traitCollection
}
}
没有成功。我该如何解决这种错位?
【问题讨论】:
标签:
ios
swift
xcode
uitabbar
【解决方案1】:
检查这是否有效,根据您想要的位置更改 UIOffset 中的值。
if #available(iOS 13, *) {
let appearance = UITabBarAppearance()
// set padding between tabbar item title and image
appearance.stackedLayoutAppearance.selected.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: 4)
appearance.stackedLayoutAppearance.normal.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: 4)
self.tabBar.standardAppearance = appearance
} else {
// set padding between tabbar item title and image
UITabBarItem.appearance().titlePositionAdjustment = UIOffset(horizontal: 0, vertical: 4)
}