Change the color of the magnifier

The color of the magnifying glass is taken automatically from the background color of the UITextView. In a text view, I have an image, and the background of the text view itself is opaque. Therefore, in this case, the magnifying glass is white, even if the image under the UITextView is yellow.

Can I override the color of a magnifying glass?

Thanks in advance.

+3
source share
5 answers

At the time of writing, this was not possible on a non-jailbroken iPhone.

Now see the answer from @ Parthpatel1105

-1
source

You can change the color to increase the search.

- (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 submit the image object to the 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];
+2
source

UITextView/UITextField, -drawRect , .backgroundColor .

0

. , " ", , "".

0

iOS 5, API:

UISearchBar.setImage(:forSearchBarIcon:state:)

. , , , .

0

Source: https://habr.com/ru/post/1710183/


All Articles