TabBar项目标题问题

TabBar项目标题问题

本文介绍了iOS13中的iOS TabBar项目标题问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在从Xcode 11进行编译时,iOS13的tabBar标题出现问题.在从Xcode 10进行编译时,它可以正常工作.请找到此问题的屏幕截图,以下是自定义tabBar的代码.

I am having issue in tabBar title for iOS13 on compiling from Xcode 11.It works perfect whle compiling from Xcode 10.Please find the screenshot for the issue and below is the code for customising the tabBar.

代码是

self.tabBar.isTranslucent = true
self.tabBar.tintColor = UIColor.white
UITabBarItem.appearance().badgeColor = Constant.Colors.colorFF1744
if #available(iOS 13, *) {
    let appearance = UITabBarAppearance.init()
    appearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.font:UIFont(name: Constant.FontNames.RubikRegular, size: Constant.FontSize.P5heading)!,NSAttributedString.Key.foregroundColor:Constant.Colors.color8D8D8D]
    appearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.font:UIFont(name: Constant.FontNames.RubikRegular, size:Constant.FontSize.P5heading)!,NSAttributedString.Key.foregroundColor:Constant.Colors.colorFF1744]
    appearance.stackedItemPositioning = .automatic
    self.tabBar.standardAppearance = appearance
} else {
    UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font:UIFont(name: Constant.FontNames.RubikRegular, size: Constant.FontSize.P5heading)!, NSAttributedString.Key.foregroundColor:Constant.Colors.color8D8D8D], for: .normal)
    UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font:UIFont(name: Constant.FontNames.RubikRegular, size: Constant.FontSize.P5heading)!, NSAttributedString.Key.foregroundColor:Constant.Colors.colorFF1744], for: .selected)
}

推荐答案

删除您的if #available(iOS 13, *),并以与在iOS 12中相同的方式进行操作.新方法UITabBarAppearance充满了错误.在固定之前,请避免使用它.

Remove your if #available(iOS 13, *) and do this the same way you were doing it in iOS 12. The new way, UITabBarAppearance, is full of bugs. Avoid it until they are fixed.

这篇关于iOS13中的iOS TabBar项目标题问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 12:42