Created
March 16, 2016 08:10
-
-
Save wuyongrui/9d4749c7b73a3e6df766 to your computer and use it in GitHub Desktop.
UIViewController Category to setup tabbarItem
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
| 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