【IOS】IOS8 TabBarItem設置自定義圖片問題


1 //IOS8以前使用的是:
2 
3 UITabBarItem *photoItem = [[UITabBarItem alloc] initWithTitle:@"首頁" image:[UIImage imageNamed:@"app2"] tag:0];
4 
5 photo.tabBarItem = photoItem;
6 
7 [photo.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"app1"] withFinishedUnselectedImage:[UIImage imageNamed:@"app2"]];
8 
9 [photoItem release];
  •  查看API之后看到使用了新的API方法
1 //使用新的API方法來初始化tabBarItem
2 - (instancetype)initWithTitle:(NSString *)title image:(UIImage *)image selectedImage:(UIImage *)selectedImage
3 //同時對使用的UIImage設置一下UIImageRenderingMode,使用UIImageRenderingModeAlwaysOriginal
4 
5 //用例:
6 UIImage * normalImage = [[UIImage imageNamed:@"nor.png"]  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
7 UIImage * selectImage = [[UIImage imageNamed:@"select.png"]  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
8      
9 UITabBarItem * tabBarItem = [[UITabBarItem alloc]initWithTitle:@"" image:normalImage selectedImage:selectImage];

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM