1

I set constraints for tabar but its image and title is showing like this only on iPhone X. Also, it is working properly on other devices like the 8, 6, and 5 series. It is not in proper format, Please suggest what I can do for it.

image

rmaddy
  • 314,917
  • 42
  • 532
  • 579

2 Answers2

2

I tend to use the view inspector to look at the frames to see what is going on. It looks like you might be doing something at the wrong time in the views life cycle. So that objects have not had time to layout.

You could also try moving the tab bar up one pixel like Uday said.

Last tip when dealing with view issues. Make sure to delete the app from the simulator on say the iPhone 8. As well as Derived Data. I have spent a lot of time trying to diagnose an issue. Only to find out I was looking at a cached storyboard.

jeremy wilson
  • 136
  • 1
  • 5
0

I found the easiest way to fix the Tabbar design for all size of iPhone. you can use setItems:animated: method of the tab bar as like below:

 func setItems(_ items: [UITabBarItem]?, animated: Bool) {
    UIIImage * image0 = UIImage(named: "search_icon")
    let item0 = UITabBarItem(title: tabBar.items[0]?.title, image: image0, tag: 0)
        // And so on or in a loop
    let items = [item0]
    // Add all items here
    tabBar.setItems(items, animated: false)
}

For more details you can read apple documentation here: https://developer.apple.com/documentation/uikit/uitabbar?language=objc

Yash
  • 171
  • 2
  • 8