Skip to content

Instantly share code, notes, and snippets.

@Lancewer
Last active December 20, 2017 23:38
Show Gist options
  • Save Lancewer/9416d51f001e26b9cf636277fe2763cf to your computer and use it in GitHub Desktop.
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
解决自定义TabBarItem中图片设置的问题,以及TabBarItem按钮超出边界的解决方式
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