Skip to content

Instantly share code, notes, and snippets.

@geek1706
Last active July 24, 2018 01:44
Show Gist options
  • Select an option

  • Save geek1706/635a2a55ec6619544d1e3e04c70bc5da to your computer and use it in GitHub Desktop.

Select an option

Save geek1706/635a2a55ec6619544d1e3e04c70bc5da to your computer and use it in GitHub Desktop.
Remove title of tab bar items and centering images
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
// iOS 11: puts the titles to the right of image for horizontal size class regular. Only want offset when compact.
// iOS 9 & 10: always puts titles under the image. Always want offset.
var verticalOffset: CGFloat = 6.0
if #available(iOS 11.0, *), traitCollection.horizontalSizeClass == .regular {
verticalOffset = 0.0
}
let imageInset = UIEdgeInsets(
top: verticalOffset,
left: 0.0,
bottom: -verticalOffset,
right: 0.0
)
for tabBarItem in tabBar.items ?? [] {
tabBarItem.title = ""
tabBarItem.imageInsets = imageInset
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment