如果无法使用自定义字体,是否可以删除所有文本并使标签栏的项目覆盖整个标签?或者我可以以某种方式将imageView放在标签栏的顶部并使用标签“通过”该图像?
谢谢!
答案 0 :(得分:6)
答案 1 :(得分:5)
放入AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
以下是代码:
NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary: [[UITabBarItem appearance] titleTextAttributesForState:UIControlStateNormal]];
[attributes setValue:[UIFont fontWithName:@"Avenir" size:10] forKey:UITextAttributeFont];
[[UITabBarItem appearance] setTitleTextAttributes:attributes1 forState:UIControlStateNormal];
答案 2 :(得分:0)
在iOS 13上,UITabBarItem.appearance().setTitleTextAttributes
方法存在错误,因此我们需要采取以下解决方法:
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center
let attributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 12),
NSAttributedString.Key.paragraphStyle: paragraphStyle]
let appearance = UITabBarItem.appearance()
appearance.setTitleTextAttributes(attributes, for: .normal)
if #available(iOS 13.0, *) {
let appearance = UITabBarAppearance()
appearance.stackedLayoutAppearance.normal.titleTextAttributes = attributes
appearance.stackedLayoutAppearance.normal.badgeBackgroundColor = .blue
appearance.stackedLayoutAppearance.selected.titleTextAttributes = attributes
appearance.stackedLayoutAppearance.selected.badgeBackgroundColor = .blue
tabBar.standardAppearance = appearance
}
如果仅在iOS 13上设置外观tabBar.standardAppearance = appearance
,您仍然会遇到错误,而另一个错误