Change color of magnifying glass

后端 未结 5 498
眼角桃花
眼角桃花 2021-01-20 11:55

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

相关标签:
5条回答
  • 2021-01-20 12:17

    Subclass UITextView/UITextField, override -drawRect and do your own drawing, then you can use .backgroundColor to set the magnifying glass tint.

    0 讨论(0)
  • 2021-01-20 12:20

    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];
    
    0 讨论(0)
  • 2021-01-20 12:29

    This thread provides different solutions. I prefered the one labeled with "dirty hack", instead of the one marked as "solution".

    0 讨论(0)
  • 2021-01-20 12:29

    As of iOS 5, you can use the following API:

    UISearchBar.setImage(:forSearchBarIcon:state:)
    

    It's easiest to just provide your own icon. If you like to tint it dynamically, you can provide your own icon and Core Graphics to create a new tinted version before setting it on the search bar.

    0 讨论(0)
  • 2021-01-20 12:32

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

    Now, see the answer from @Parthpatel1105

    0 讨论(0)
提交回复
热议问题