【发布时间】:2021-05-01 03:53:55
【问题描述】:
我试图让所有用户都可以访问我的应用程序,但在为 TabBar 创建项目时偶然发现了一个问题,我很想有办法解决它。
我的项目中有这样的东西:
func setupTabBarItems(tabName: String, tabImage: UIImage?, tabSelectedImage: UIImage?) {
let tabBarItem = UITabBarItem(title: tabName, image: tabImage, selectedImage: tabSelectedImage)
tabBarItem.title = tabName
tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: AppColor.primary], for: .selected)
tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: AppColor.darkDeep], for: .normal)
tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font: AppFont.medium(12)], for: .normal)
tabBarItem.imageInsets = UIEdgeInsets.init(top: -10, left: 0, bottom: 0, right: 0)
tabBarItem.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -18)
DispatchQueue.main.async {
self.navigationController.tabBarItem = tabBarItem
}
}
和:
static func medium(_ fontSize: CGFloat) -> UIFont {
let font = UIFont(name: AppFont.someRandomTextFont, size: fontSize)!
let fontMetrics = UIFontMetrics(forTextStyle: .body)
return fontMetrics.scaledFont(for: font)
}
当增加dynamic text type 时,title 会脱离实际项目。
例如,当为UILabel 执行此操作时,我只需检查“Automatically Adjust Font”选项并将“Minimum Font Scale”更新为 0.25。
有没有办法在以编程方式描述TabBarItem的代码中做这样的事情?
非常感谢!
【问题讨论】:
标签: ios swift accessibility uitabbaritem dynamic-type-feature