Last active
July 24, 2018 01:44
-
-
Save geek1706/635a2a55ec6619544d1e3e04c70bc5da to your computer and use it in GitHub Desktop.
Remove title of tab bar items and centering images
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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