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

      1. <tfoot id='unITV'></tfoot>

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

          <bdo id='unITV'></bdo><ul id='unITV'></ul>

        带有 GradientLayer 的 UIButton 使图像模糊并使渐变变暗

        UIButton with GradientLayer obscures image and darkens gradient(带有 GradientLayer 的 UIButton 使图像模糊并使渐变变暗)
          <tbody id='Sujw3'></tbody>
          <bdo id='Sujw3'></bdo><ul id='Sujw3'></ul>

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

                • <small id='Sujw3'></small><noframes id='Sujw3'>

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

                • 本文介绍了带有 GradientLayer 的 UIButton 使图像模糊并使渐变变暗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在这里有一个 UIButton,我希望将渐变作为图像下方的背景(具有透明背景的符号),但我面临两个不同的问题.

                  I have an UIButton here where I'd like to have a gradient as the background below the image (symbol with transparent background), but I'm facing two different problems.

                  无论我如何尝试添加,CAGradientLayer 的第一个似乎都覆盖在图像之上,完全遮蔽了图像.

                  First of the CAGradientLayer seems to overlay on top of the image no matter how I try to add it, obscuring the image completely.

                  其次,渐变本身似乎变暗了很多,就像按钮被禁用一样,但事实并非如此.

                  Secondly the gradient itself seems to be darkened a lot, like the button was disabled, which it isn't.

                  这是我的代码:

                  self.backButton = [[UIButton alloc] initWithFrame:CGRectMake(15, 35, 28, 28)];
                  [backButton addTarget:self
                                 action:@selector(goBack)
                       forControlEvents:UIControlEventTouchUpInside];
                  [backButton setBackgroundColor:[UIColor clearColor]];
                  CAGradientLayer *buttonGradient = [CAGradientLayer layer];
                  buttonGradient.frame = backButton.bounds;
                  buttonGradient.colors = [NSArray arrayWithObjects:
                                           (id)[[UIColor colorWithRed:.0
                                                                green:.166
                                                                 blue:.255
                                                                alpha:1] CGColor], 
                                           (id)[[UIColor colorWithRed:.0
                                                                green:.113
                                                                 blue:.255
                                                                alpha:1] CGColor], 
                                           nil];
                  [buttonGradient setCornerRadius:backButton.frame.size.width / 2];
                  [backButton.layer insertSublayer:buttonGradient
                                           atIndex:0];
                  [backButton setImage:[UIImage imageNamed:@"backarrow.png"]
                              forState:UIControlStateNormal];
                  [backButton setEnabled:NO];
                  [topbarView addSubview:backButton];
                  

                  推荐答案

                  所以我设法通过在添加渐变后执行 [button bringSubviewToFront:button.imageView] 来解决这个问题.似乎无论我做什么,新层都会添加到 imageView 之上,所以我需要在之后将它推到前面.

                  So I managed to get around this by doing a [button bringSubviewToFront:button.imageView] after adding the gradient. Seems that no matter what I do the new layer will add on top of the imageView, so I need to push that to the front afterwards.

                  目标-C:

                  [button bringSubviewToFront:button.imageView] 
                  

                  Swift 4.1:

                  button.bringSubview(toFront:button.imageView!)
                  

                  这篇关于带有 GradientLayer 的 UIButton 使图像模糊并使渐变变暗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  UIButton title text color(UIButton 标题文本颜色)
                  Stretch background image for UIButton(为 UIButton 拉伸背景图像)
                  Using Tint color on UIImageView(在 UIImageView 上使用 Tint 颜色)
                  How can I change UIButton title color?(如何更改 UIButton 标题颜色?)
                  iPhone UIButton - image position(iPhone UIButton - 图像位置)
                  UIButton remove all target-actions(UIButton 删除所有目标动作)

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

                        <tbody id='l1OIv'></tbody>

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

                          <tfoot id='l1OIv'></tfoot>

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