2009-06-10 91 views
3

放大鏡的顏色是從UITextView的背景顏色自動獲取的。 在文本視圖下,我有一個圖像,文本視圖背景本身是不透明的。所以在這種情況下,即使UITextView下的圖片爲黃色,放大鏡也是白色的。更換放大鏡的顏色

是否可以重寫放大鏡的顏色?

預先感謝您。

回答

-1

在編寫本文時,它不可能在非越獄iPhone上使用。

現在,看到@ Parthpatel1105

0

子類UITextView/UITextField答案,覆蓋-drawRect,做自己的繪圖,那麼你可以使用.backgroundColor設置放大鏡色調。

+0

這實際上工作嗎? – Meltemi 2010-03-18 02:54:30

0

This線程提供了不同的解決方案。我更喜歡那個標有「骯髒的黑客」的標籤,而不是標註爲「解決方案」的標籤。

2

可以改變搜索放大的顏色。

- (UIImage *)tintedImageWithColor:(UIColor *)tintColor image:(UIImage *)image { 
UIGraphicsBeginImageContextWithOptions(image.size, NO, [[UIScreen mainScreen] scale]); 
CGContextRef context = UIGraphicsGetCurrentContext(); 

CGContextTranslateCTM(context, 0, image.size.height); 
CGContextScaleCTM(context, 1.0, -1.0); 

CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height); 

// draw alpha-mask 
CGContextSetBlendMode(context, kCGBlendModeNormal); 
CGContextDrawImage(context, rect, image.CGImage); 

// draw tint color, preserving alpha values of original image 
CGContextSetBlendMode(context, kCGBlendModeSourceIn); 
[tintColor setFill]; 
CGContextFillRect(context, rect); 

UIImage *coloredImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
return coloredImage; 

}

使用當你通過圖像對象來搜索欄此行。

UIImage *obj_image = [self tintedImageWithColor:[appDelegate.appDefaultdata valueForKey:@"d_colorA"] image:[UIImage imageNamed:@"search_magnify.png"]]; 
[contactSearchbar setImage:obj_image forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal]; 
0

隨着iOS 5的,你可以使用下面的API:

UISearchBar.setImage(:forSearchBarIcon:state:) 

這是最簡單的,只是提供自己的圖標。如果您想動態調色,您可以提供自己的圖標和Core Graphics來創建新的有色版本,然後將其設置在搜索欄上。