tabbar 藍色

今天在UITabBarController使用自定義圖片設置UITabItem時,發(fā)現一個問題:

在iOS7以上的手機中,第一個Tab的選中圖一直顯示的是系統(tǒng)默認的藍色圖,查看了一下UITabItem的頭文件,發(fā)現下面的內容:


/* The unselected image is autogenerated from the image argument. The selected image

is autogenerated from the selectedImage if provided and the image argument otherwise.

To prevent system coloring, provide images with UIImageRenderingModeAlwaysOriginal (see UIImage.h)

*/

- (instancetype)initWithTitle:(NSString *)title image:(UIImage *)image tag:(NSInteger)tag;

- (instancetype)initWithTitle:(NSString *)title image:(UIImage *)image selectedImage:(UIImage *)selectedImage NS_AVAILABLE_IOS(7_0);

- (instancetype)initWithTabBarSystemItem:(UITabBarSystemItem)systemItem tag:(NSInteger)tag;

意思是,如果不希望使用系統(tǒng)顏色,需要對圖片加上屬性UIImageRenderingModeAlwaysOriginal

所以按此方式實驗,代碼如下:

UIImage *musicImage = [UIImage imageNamed:@"music.png"];

UIImage *musicImageSel = [UIImage imageNamed:@"musicSel.png"];

musicImage = [musicImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

musicImageSel = [musicImageSel imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

self.musicViewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Music" image:musicImage selectedImage:musicImageSel];

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容