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

  • <tfoot id='CMLSy'></tfoot>

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

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

        颜色色调 UIButton 图像

        时间:2023-07-09

        <small id='4G7Bs'></small><noframes id='4G7Bs'>

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

              <legend id='4G7Bs'><style id='4G7Bs'><dir id='4G7Bs'><q id='4G7Bs'></q></dir></style></legend>
                  <tbody id='4G7Bs'></tbody>
                  <bdo id='4G7Bs'></bdo><ul id='4G7Bs'></ul>
                  本文介绍了颜色色调 UIButton 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我注意到,当我将白色或黑色 UIImage 放入 UISegmentedControl 时,它会自动对其进行颜色遮罩以匹配分段控件的色调.我认为这真的很酷,并且想知道我是否也可以在其他地方这样做.例如,我有一堆形状统一但颜色多样的按钮.除了为每个按钮制作一个 PNG 之外,我是否可以以某种方式使用这种颜色遮罩为所有按钮使用相同的图像,然后设置一个色调颜色或其他东西来改变它们的实际颜色?

                  I noticed that when I place a white or black UIImage into a UISegmentedControl it automatically color masks it to match the tint of the segmented control. I thought this was really cool, and was wondering if I could do this elsewhere as well. For example, I have a bunch of buttons that have a uniform shape but varied colors. Instead of making a PNG for each button, could I somehow use this color masking to use the same image for all of them but then set a tint color or something to change their actual color?

                  推荐答案

                  从 iOS 7 开始,UIImage 上有一个新方法来指定渲染模式.使用渲染模式 UIImageRenderingModeAlwaysTemplate 将允许图像颜色由按钮的色调颜色控制.

                  As of iOS 7, there is a new method on UIImage to specify the rendering mode. Using the rendering mode UIImageRenderingModeAlwaysTemplate will allow the image color to be controlled by the button's tint color.

                  目标-C

                  UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                  UIImage *image = [[UIImage imageNamed:@"image_name"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
                  [button setImage:image forState:UIControlStateNormal]; 
                  button.tintColor = [UIColor redColor];
                  

                  斯威夫特

                  let button = UIButton(type: .custom)
                  let image = UIImage(named: "image_name")?.withRenderingMode(.alwaysTemplate)
                  button.setImage(image, for: .normal)
                  button.tintColor = UIColor.red
                  

                  这篇关于颜色色调 UIButton 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:触摸后保持 UIButton 处于选中状态 下一篇:如何以编程方式将触摸事件伪造为 UIButton?

                  相关文章

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

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

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