<i id='QEayK'><tr id='QEayK'><dt id='QEayK'><q id='QEayK'><span id='QEayK'><b id='QEayK'><form id='QEayK'><ins id='QEayK'></ins><ul id='QEayK'></ul><sub id='QEayK'></sub></form><legend id='QEayK'></legend><bdo id='QEayK'><pre id='QEayK'><center id='QEayK'></center></pre></bdo></b><th id='QEayK'></th></span></q></dt></tr></i><div id='QEayK'><tfoot id='QEayK'></tfoot><dl id='QEayK'><fieldset id='QEayK'></fieldset></dl></div>

    • <bdo id='QEayK'></bdo><ul id='QEayK'></ul>
    <tfoot id='QEayK'></tfoot><legend id='QEayK'><style id='QEayK'><dir id='QEayK'><q id='QEayK'></q></dir></style></legend>
    1. <small id='QEayK'></small><noframes id='QEayK'>

      如何在 UIImage 上像 UIButton 一样在点击时实现突出显示?

      时间:2023-07-08
          <bdo id='NbLKo'></bdo><ul id='NbLKo'></ul>
          <i id='NbLKo'><tr id='NbLKo'><dt id='NbLKo'><q id='NbLKo'><span id='NbLKo'><b id='NbLKo'><form id='NbLKo'><ins id='NbLKo'></ins><ul id='NbLKo'></ul><sub id='NbLKo'></sub></form><legend id='NbLKo'></legend><bdo id='NbLKo'><pre id='NbLKo'><center id='NbLKo'></center></pre></bdo></b><th id='NbLKo'></th></span></q></dt></tr></i><div id='NbLKo'><tfoot id='NbLKo'></tfoot><dl id='NbLKo'><fieldset id='NbLKo'></fieldset></dl></div>
          <legend id='NbLKo'><style id='NbLKo'><dir id='NbLKo'><q id='NbLKo'></q></dir></style></legend>

            <tbody id='NbLKo'></tbody>

          <tfoot id='NbLKo'></tfoot>

                <small id='NbLKo'></small><noframes id='NbLKo'>

                本文介绍了如何在 UIImage 上像 UIButton 一样在点击时实现突出显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我需要复制 UIButton 在点击时对图像的效果,即突出显示.见:

                I need to replicate the effect that the UIButton does on an image when tapped, the highlighting. See:

                原始 PNG 是一个带有 alpha 背景的正方形.当我将它设置为 UIButton 的图像时,它会自动对图像的非 alpha 像素应用效果.

                The original PNG is a square with alpha background. When I set it as UIButton's image it automatically apply an effect on the non-alpha pixels of the image.

                这个效果怎么做?

                推荐答案

                您可以通过 UIImage 上的简单类别来实现:

                You could achieve this with a simple category on UIImage:

                @interface UIImage (Tint)
                
                - (UIImage *)tintedImageUsingColor:(UIColor *)tintColor;
                
                @end
                
                @implementation UIImage (Tint)
                
                - (UIImage *)tintedImageUsingColor:(UIColor *)tintColor {
                  UIGraphicsBeginImageContextWithOptions(self.size, NO, self.scale);
                  CGRect drawRect = CGRectMake(0, 0, self.size.width, self.size.height);
                  [self drawInRect:drawRect];
                  [tintColor set];
                  UIRectFillUsingBlendMode(drawRect, kCGBlendModeSourceAtop);
                  UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
                  UIGraphicsEndImageContext();
                  return tintedImage;
                }
                
                @end
                

                对于上面显示的效果,您需要传递类似 [UIColor colorWithWhite:0.0 alpha:0.3] 作为 tintColor 参数(使用 alpha 值进行实验).

                For the effect shown above, you'd pass something like [UIColor colorWithWhite:0.0 alpha:0.3] as the tintColor parameter (experiment with the alpha value).

                这篇关于如何在 UIImage 上像 UIButton 一样在点击时实现突出显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:UITableViewCell 中的 UIButton 下一篇:动画 UIButton 状态变化

                相关文章

                <legend id='k4XOY'><style id='k4XOY'><dir id='k4XOY'><q id='k4XOY'></q></dir></style></legend>

                <small id='k4XOY'></small><noframes id='k4XOY'>

                  <i id='k4XOY'><tr id='k4XOY'><dt id='k4XOY'><q id='k4XOY'><span id='k4XOY'><b id='k4XOY'><form id='k4XOY'><ins id='k4XOY'></ins><ul id='k4XOY'></ul><sub id='k4XOY'></sub></form><legend id='k4XOY'></legend><bdo id='k4XOY'><pre id='k4XOY'><center id='k4XOY'></center></pre></bdo></b><th id='k4XOY'></th></span></q></dt></tr></i><div id='k4XOY'><tfoot id='k4XOY'></tfoot><dl id='k4XOY'><fieldset id='k4XOY'></fieldset></dl></div>
                  • <bdo id='k4XOY'></bdo><ul id='k4XOY'></ul>

                    <tfoot id='k4XOY'></tfoot>