iosswiftuikituitabbaritem

In iPad the title text of UITabBaritems of my app is showing truncated, Working fine in iPhone


Tabbar item text is showing truncated on an iPad but on an iPhone it's Working fine.

Here is my Code:

class HomeTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let tabBarAppearnace = UITabBarAppearance()
        let tabFont =  UIFont.boldSystemFont(ofSize: 18)
        
        let selectedAttributes: [NSAttributedString.Key: Any]
        = [NSAttributedString.Key.font: tabFont, NSAttributedString.Key.foregroundColor: UIColor.orange]
        let normalAttributes: [NSAttributedString.Key: Any]
        = [NSAttributedString.Key.font: tabFont, NSAttributedString.Key.foregroundColor: UIColor.black]
        
        tabBarAppearnace.stackedLayoutAppearance.normal.titleTextAttributes = normalAttributes
        tabBarAppearnace.stackedLayoutAppearance.selected.titleTextAttributes = selectedAttributes
        
        //New        
        tabBarAppearnace.inlineLayoutAppearance.normal.titleTextAttributes = normalAttributes
        tabBarAppearnace.inlineLayoutAppearance.selected.titleTextAttributes = selectedAttributes

        tabBarAppearnace.compactInlineLayoutAppearance.normal.titleTextAttributes = normalAttributes
        tabBarAppearnace.compactInlineLayoutAppearance.selected.titleTextAttributes = selectedAttributes


        tabBar.standardAppearance = tabBarAppearnace
    }
}

Solution

  • let normalAttrs: [NSAttributedString.Key: Any] = [.foregroundColor: ThemeColor.gray, .paragraphStyle: NSParagraphStyle.default]
    let selectedAttrs: [NSAttributedString.Key: Any] = [.foregroundColor: ThemeColor.red, .paragraphStyle: NSParagraphStyle.default]