Last active
December 20, 2017 23:38
-
-
Save Lancewer/9416d51f001e26b9cf636277fe2763cf to your computer and use it in GitHub Desktop.
[Customize UITabBarItem] customize UITabBarItem with image and text color #UITabBarItem #customize #Appearence #Image
This file contains 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
解决自定义TabBarItem中图片设置的问题,以及TabBarItem按钮超出边界的解决方式 |
This file contains 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
func setupTabBarItem(){ | |
var defaultIconImage = UIImage(named: "035") | |
if let image = defaultIconImage { | |
defaultIconImage = image.withRenderingMode(.alwaysOriginal) //Keep image render model original is important! | |
} | |
var selectedIconImage = UIImage(named: "020") | |
if let image = selectedIconImage { | |
selectedIconImage = image.withRenderingMode(.alwaysOriginal) | |
} | |
let tabBarItem:UITabBarItem = UITabBarItem(title: "Add", image: defaultIconImage, selectedImage: selectedIconImage) | |
tabBarItem.imageInsets = UIEdgeInsetsMake(-10, 0, 10, 0) | |
UITabBarItem.appearance().setTitleTextAttributes( | |
[NSAttributedStringKey.foregroundColor : UIColor.red], | |
for: .normal) | |
UITabBarItem.appearance().setTitleTextAttributes( | |
[NSAttributedStringKey.foregroundColor : UIColor.green], | |
for: .selected) | |
self.tabBarItem = tabBarItem | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment