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

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

      <tfoot id='gniMG'></tfoot>
    1. <legend id='gniMG'><style id='gniMG'><dir id='gniMG'><q id='gniMG'></q></dir></style></legend>

      • <bdo id='gniMG'></bdo><ul id='gniMG'></ul>
      1. 如何设置 UIButton 图像,该图像是带边框的圆形

        How can I set UIButton image, which Image is round shape with border(如何设置 UIButton 图像,该图像是带边框的圆形)

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

                  <tbody id='o3kut'></tbody>
              1. <legend id='o3kut'><style id='o3kut'><dir id='o3kut'><q id='o3kut'></q></dir></style></legend>

                • <bdo id='o3kut'></bdo><ul id='o3kut'></ul>
                  <tfoot id='o3kut'></tfoot>

                  <i id='o3kut'><tr id='o3kut'><dt id='o3kut'><q id='o3kut'><span id='o3kut'><b id='o3kut'><form id='o3kut'><ins id='o3kut'></ins><ul id='o3kut'></ul><sub id='o3kut'></sub></form><legend id='o3kut'></legend><bdo id='o3kut'><pre id='o3kut'><center id='o3kut'></center></pre></bdo></b><th id='o3kut'></th></span></q></dt></tr></i><div id='o3kut'><tfoot id='o3kut'></tfoot><dl id='o3kut'><fieldset id='o3kut'></fieldset></dl></div>
                • 本文介绍了如何设置 UIButton 图像,该图像是带边框的圆形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何设置 UIButton 图像,该图像是带边框的圆形我编写了相关代码,但图像没有以正确的圆形显示..这是我的代码..

                  How can I set UIButton image, which Image is round shape with border I write related code but image not displaying in proper round shape.. Here is my code..

                      btnMyProfile.setImage(UIImage(named: "MyDefaultImg.png"), for: .normal)
                      btnMyProfile.imageView?.contentMode = .scaleAspectFit
                      btnMyProfile.imageView?.layer.cornerRadius = (btnMyProfile.imageView?.frame.width)! / 2
                      btnMyProfile.imageView?.layer.borderColor = UIColor.blue.cgColor
                      btnMyProfile.imageView?.layer.borderWidth = 2.0
                  

                  我的 o/p 看起来像这样..

                  My o/p look like this..

                  但我需要这样..

                  我可以做些什么来实现我想要的输出?

                  What can I do for achieve my desired output?

                  推荐答案

                  为你的 imageview 设置 clipsToBounds = true

                  set clipsToBounds = true for your imageview

                  btnMyProfile.imageView.clipsToBounds = true
                  

                  或使用

                  btnMyProfile.imageView.layer.masksToBounds = true
                  

                  来自 苹果文档:

                  默认情况下,圆角半径不适用于图层的内容属性;它仅适用于背景颜色和层的边界.但是,将 maskToBounds 属性设置为true 导致内容被剪裁到圆角.

                  By default, the corner radius does not apply to the image in the layer’s contents property; it applies only to the background color and border of the layer. However, setting the masksToBounds property to true causes the content to be clipped to the rounded corners.

                  其他选项使用 UIBezierPath

                  这篇关于如何设置 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 删除所有目标动作)
                    <tfoot id='y4YyL'></tfoot>
                    <i id='y4YyL'><tr id='y4YyL'><dt id='y4YyL'><q id='y4YyL'><span id='y4YyL'><b id='y4YyL'><form id='y4YyL'><ins id='y4YyL'></ins><ul id='y4YyL'></ul><sub id='y4YyL'></sub></form><legend id='y4YyL'></legend><bdo id='y4YyL'><pre id='y4YyL'><center id='y4YyL'></center></pre></bdo></b><th id='y4YyL'></th></span></q></dt></tr></i><div id='y4YyL'><tfoot id='y4YyL'></tfoot><dl id='y4YyL'><fieldset id='y4YyL'></fieldset></dl></div>
                  • <small id='y4YyL'></small><noframes id='y4YyL'>

                        <tbody id='y4YyL'></tbody>
                      <legend id='y4YyL'><style id='y4YyL'><dir id='y4YyL'><q id='y4YyL'></q></dir></style></legend>
                          <bdo id='y4YyL'></bdo><ul id='y4YyL'></ul>