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

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

    <legend id='u2i8l'><style id='u2i8l'><dir id='u2i8l'><q id='u2i8l'></q></dir></style></legend>
      • <bdo id='u2i8l'></bdo><ul id='u2i8l'></ul>

        iPhone iOS如何在按钮的文本或图像下向UIButton添加线性渐变?

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

              <tbody id='iBV7r'></tbody>
          • <tfoot id='iBV7r'></tfoot>

              • <bdo id='iBV7r'></bdo><ul id='iBV7r'></ul>
                1. <small id='iBV7r'></small><noframes id='iBV7r'>

                  本文介绍了iPhone iOS如何在按钮的文本或图像下向UIButton添加线性渐变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在通过向按钮添加线性渐变来创建精美的 UI 按钮.但是我不确定我需要在哪个索引处添加渐变.我目前拥有的代码将渐变放在图像/文本上.

                  I'm working on creating fancy looking UIbuttons by adding linear gradient to the button. However I'm not sure at which index I need to add the gradient. The code that I have currently places the gradient over the image/text.

                  如何在文本/图像子层下的 UIButton 中插入子层?保持按钮的文本和图像可见对我来说很重要!

                  How can I insert a sublayer to a UIButton under the text/image sublayer? It is important for me to keep the text and the image of a button visible!

                  +(void)addLinearGradientToView:(UIView*)view TopColor:(UIColor*)topColor BottomColor:(UIColor*)bottomColor
                  {
                      for(CALayer* layer in view.layer.sublayers)
                      {
                          if ([layer isKindOfClass:[CAGradientLayer class]])
                          {
                              [layer removeFromSuperlayer];
                          }
                      }
                      CAGradientLayer* gradientLayer = [CAGradientLayer layer];
                  
                      gradientLayer.startPoint = CGPointMake(0.5, 0);
                      gradientLayer.endPoint = CGPointMake(0.5,1);
                      gradientLayer.frame = view.bounds;
                      gradientLayer.colors = [NSArray arrayWithObjects:(id)[topColor CGColor], (id)[bottomColor CGColor], nil];
                      //    [view.layer addSublayer:gradientLayer];
                      if(view.layer.sublayers.count>0)
                      {
                          [view.layer insertSublayer:gradientLayer atIndex:view.layer.sublayers.count-2];
                      }else {
                          [view.layer addSublayer:gradientLayer];
                      }
                  }
                  

                  推荐答案

                  将其添加到自定义按钮的层:

                  Add it to the layer of your custom button:

                  CAGradientLayer *gradientLayer = [CAGradientLayer layer];
                  gradientLayer.frame = customButton.layer.bounds;
                  
                  gradientLayer.colors = [NSArray arrayWithObjects:
                                          (id)[UIColor colorWithWhite:1.0f alpha:0.1f].CGColor,
                                          (id)[UIColor colorWithWhite:0.4f alpha:0.5f].CGColor,
                                          nil];
                  
                  gradientLayer.locations = [NSArray arrayWithObjects:
                                             [NSNumber numberWithFloat:0.0f],
                                             [NSNumber numberWithFloat:1.0f],
                                             nil];
                  
                  gradientLayer.cornerRadius = customButton.layer.cornerRadius;
                  [customButton.layer addSublayer:gradientLayer];
                  

                  其中 customButton 是您的自定义 UIButton.

                  where customButton is your custom UIButton.

                  这篇关于iPhone iOS如何在按钮的文本或图像下向UIButton添加线性渐变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在 UIButton 上仅添加 TOP 边框? 下一篇:与 NSAttributedString 真的很接近吗?

                  相关文章

                2. <tfoot id='UBMl9'></tfoot>

                  1. <small id='UBMl9'></small><noframes id='UBMl9'>

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