Skip to content

Instantly share code, notes, and snippets.

@wuyongrui
Created March 16, 2016 08:10
Show Gist options
  • Select an option

  • Save wuyongrui/9d4749c7b73a3e6df766 to your computer and use it in GitHub Desktop.

Select an option

Save wuyongrui/9d4749c7b73a3e6df766 to your computer and use it in GitHub Desktop.
UIViewController Category to setup tabbarItem
public extension UIViewController {
public func setTabbarItem(title title:String,imageName:String!,selectedImageName:String!) {
self.tabBarItem.title = title
if imageName != nil {
self.tabBarItem.image = UIImage(named:imageName)
}
if selectedImageName != nil {
// self.tabBarItem.selectedImage = UIImage(named:selectedImageName)
self.tabBarItem.selectedImage = UIImage(named:selectedImageName)!.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal) // 使用原图片,不被tintColor影响
}
}
}
/// usage
class FirstViewController:UIViewController {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setTabbarItem(title: "title", imageName: "image", selectedImageName: "selectedImage")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment