Remove tab bar item text, show only image

前端 未结 19 2167
我寻月下人不归
我寻月下人不归 2020-12-04 06:50

Simple question, how can I remove the tab bar item text and show only the image?

I want the bar items to like in the instagram app:

19条回答
  •  我在风中等你
    2020-12-04 07:20

    Custom TabBar - iOS 13, Swift 5, XCode 11

    • TabBar items without text
    • TabBar items centered vertically
    • Rounded TabBar view
    • TabBar Dynamic position and frames

    Storyboard based. It can be achieved easily programmatically too. Only 4 Steps to follow:

    1. Tab Bar Icons must be in 3 sizes, in black color. Usually, I download from fa2png.io - sizes: 25x25, 50x50, 75x75. PDF image files do not work!

    2. In Storyboard for the tab bar item set the icon you want to use through Attributes Inspector. (see screenshot)

    1. Custom TabBarController -> New File -> Type: UITabBarController -> Set on storyboard. (see screenshot)

    1. UITabBarController class

      class RoundedTabBarViewController: UITabBarController {

      override func viewDidLoad() {
          super.viewDidLoad()
      
          // Do any additional setup after loading the view.
          // Custom tab bar view
          customizeTabBarView()
      }
      
      private func customizeTabBarView() {
          let tabBarHeight = tabBar.frame.size.height
          self.tabBar.layer.masksToBounds = true
          self.tabBar.isTranslucent = true
          self.tabBar.barStyle = .default
          self.tabBar.layer.cornerRadius = tabBarHeight/2
          self.tabBar.layer.maskedCorners = [.layerMaxXMaxYCorner, .layerMaxXMinYCorner, .layerMinXMaxYCorner, .layerMinXMinYCorner]
      }
      
      override func viewDidLayoutSubviews() {
          super.viewDidLayoutSubviews()
          let viewWidth = self.view.bounds.width
          let leadingTrailingSpace = viewWidth * 0.05
      
          tabBar.frame = CGRect(x: leadingTrailingSpace, y: 200, width: viewWidth - (2 * leadingTrailingSpace), height: 49)
      }
      

      }

    2. Result

提交回复
热议问题