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

  • <small id='1ZLIU'></small><noframes id='1ZLIU'>

      <legend id='1ZLIU'><style id='1ZLIU'><dir id='1ZLIU'><q id='1ZLIU'></q></dir></style></legend>
      1. <tfoot id='1ZLIU'></tfoot>
        • <bdo id='1ZLIU'></bdo><ul id='1ZLIU'></ul>
      2. 如何使用左上角创建圆形 UIButton &amp;仅左下角半径

        时间:2023-07-06
        • <bdo id='Xioh7'></bdo><ul id='Xioh7'></ul>

              <tbody id='Xioh7'></tbody>

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

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

              • <legend id='Xioh7'><style id='Xioh7'><dir id='Xioh7'><q id='Xioh7'></q></dir></style></legend>
                • <tfoot id='Xioh7'></tfoot>
                  本文介绍了如何使用左上角创建圆形 UIButton &amp;仅左下角半径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要创建一个左上角的按钮 &像这样的左下角半径 .我尝试创建以下扩展名,该扩展名取自 stackoverflow 答案之一:

                  I need to create a button with top-left & bottom-left corner radius like this one . I tried by creating the following extension that was taken from one of stackoverflow answer:

                  extension UIButton {
                  
                     func roundCorners(corners:UIRectCorner, radius: CGFloat) {
                         self.layer.borderColor = GenerateShape.UIColorFromHex(0x989898, alpha: (1.0-0.3)).CGColor
                         self.layer.borderWidth = 1.0
                         let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
                         let mask = CAShapeLayer()
                         mask.path = path.CGPath
                         self.layer.mask = mask
                  
                     }
                  }
                  

                  然后像这样调用方法:

                  self.collectionBtn.roundCorners(.TopLeft | .BottomLeft, radius: cornerRadius) 
                  

                  此代码生成以下形状

                  那么为什么是左上角 &左下角看不见?我应该怎么做才能让它们可见?

                  So why the top-left & bottom-left corner invisible? What should I do to make them visible?

                  推荐答案

                  您的代码正在将遮罩层应用到您的按钮.这会导致您在遮罩层中安装的形状之外的任何东西都被遮盖掉.当您安装带有圆角的路径时,它基本上会刮掉"两个角.这不是你想要的.

                  Your code is applying a mask layer to your button. that causes anything outside the shape you install in the mask layer to be masked away. When you install a path with rounded corners, it essentially "shaves off" the 2 corners. That's not what you want.

                  您可能希望创建一个形状图层并将其安装为按钮图层的常规子图层,而不是蒙版图层.但是,您需要将填充颜色设置为清除.

                  You probably want to create a shape layer and install it as a regular sublayer of your button's layer, not as the mask layer. You'll need to set the fill color to clear however.

                  像这样更改您的代码:

                  extension UIButton 
                  {
                    func roundCorners(corners:UIRectCorner, radius: CGFloat) 
                    {
                      let borderLayer = CAShapeLayer()
                      borderLayer.frame = self.layer.bounds
                      borderLayer.strokeColor = GenerateShape.UIColorFromHex(0x989898, 
                        alpha: (1.0-0.3)).CGColor
                      borderLayer.fillColor = UIColor.clearColor().CGColor
                      borderLayer.lineWidth = 1.0
                      let path = UIBezierPath(roundedRect: self.bounds, 
                        byRoundingCorners: corners, 
                        cornerRadii: CGSize(width: radius, height: radius))
                      borderLayer.path = path.CGPath
                      self.layer.addSublayer(borderLayer);
                    }
                  }
                  

                  你设置角落的语法在 Swift 2 中不起作用:

                  Your syntax for setting the corners won't work in Swift 2:

                  self.collectionBtn.roundCorners(.TopLeft | .BottomLeft, radius: 10)
                  

                  应该是

                  self.collectionBtn.roundCorners([.TopLeft, .BottomLeft], radius: 10)
                  

                  这篇关于如何使用左上角创建圆形 UIButton &amp;仅左下角半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:UIButtonTypeRoundedRect 类型的 UIButton 的着色 下一篇:带有 UITableViewCellSelectionStyleGray 选择颜色的 UIButton

                  相关文章

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

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

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

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

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