iOS TabBar item title issue in iOS13

后端 未结 3 952
予麋鹿
予麋鹿 2021-02-06 09:42

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 co

3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-06 10:06

    I had a similar issue as your post. I needed to make the title bold when selected. But it became truncated, though the regular one didn't. My workaround was to give spaces to the both end of the text like "Category" -> " Category ".
    My guess was the width of regular-font box is fixed, even though it became bold-font. And it worked for my case. It's not precisely matching the case, but you may try.

    if #available(iOS 13, *) {
      let appearance = UITabBarAppearance()
      appearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 9, weight: .regular), NSAttributedString.Key.foregroundColor: UIColor.lightGray]
      appearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 9, weight: .bold), NSAttributedString.Key.foregroundColor: UIColor.red]
      appearance.stackedItemPositioning = .automatic
      tabBar.standardAppearance = appearance
    }
    

提交回复
热议问题