正如已經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
如果我理解你很可能要防止梯度。嘗試這個http://stackoverflow.com/questions/1355480/preventing-a-uitabbar-from-applying-a-gradient-to-its-icon-images – Popeye
你做了,但我寧願「反」的梯度如果可能的 – pdrcabrod