2013-01-21 23 views
1

我使用TabBarController中的selectedImageTintColor屬性更改所選TabBarItem的顏色。UITabBarItem selectedImageTintColor。如何找到設置爲tintcolor的顏色

的問題是,你設置爲tintcolor顏色不是最終顏色應用,它改變之前(它得到某種梯度)

我的問題是,是否有可能找到顏色申請作爲tintcolor獲得你知道的最終顏色?

例如,我希望我的選擇項都具有的

[UIColor colorWithRed:(154.0/255.0) green:(213.0/255.0) blue:(0.0) alpha:(1.0) 

什麼顏色位RGB我應該設置該屬性selectedImageTintColor最終顏色?

+0

如果我理解你很可能要防止梯度。嘗試這個http://stackoverflow.com/questions/1355480/preventing-a-uitabbar-from-applying-a-gradient-to-its-icon-images – Popeye

+0

你做了,但我寧願「反」的梯度如果可能的 – pdrcabrod

回答

-1

iOS不提供修改色調顏色漸變的API。不過,蘋果文檔建議使用setFinishedSelectedImage:withFinishedUnSelectedImage:方法。

看到更多UITabBarItem參考

+0

這個聲明有什麼錯誤? –

0

正如已經ANKIT說,最好的辦法是使用

- (void)setFinishedSelectedImage:(UIImage *)selectedImage withFinishedUnselectedImage:(UIImage *)unselectedImage 

不過,我很欣賞你需要有一個UIImage才能夠做到這一點。如果你的設計者不能爲你提供這個,你可以做的是在代碼中繪製你自己的UIImage。

- (UIImage *)imageWithColor:(UIColor *)color { 
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); 
    UIGraphicsBeginImageContext(rect.size); 
    CGContextRef context = UIGraphicsGetCurrentContext(); 

    CGContextSetFillColorWithColor(context, [color CGColor]); 
    CGContextFillRect(context, rect); 

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    return image; 
} 

很明顯,這段代碼並沒有給你一個漸變,但它顯示了繪製UIImage的基礎知識。我想看看類似下面的教程來解決如何吸引你想要的確切梯度:

http://www.raywenderlich.com/2033/core-graphics-101-lines-rectangles-and-gradients

相關問題