The color of a magnifying glass is being taken automatically from the background color of UITextView. Under the text view I have an image and the text view background itself
It is possible for change colour of search magnify .
- (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;
}
use this line when you pass image object to search bar.
UIImage *obj_image = [self tintedImageWithColor:[appDelegate.appDefaultdata valueForKey:@"d_colorA"] image:[UIImage imageNamed:@"search_magnify.png"]];
[contactSearchbar setImage:obj_image forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];