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

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

      • <bdo id='lQf5l'></bdo><ul id='lQf5l'></ul>

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

        <tfoot id='lQf5l'></tfoot>

        如何在 Swift 2 中制作按钮自定义形状的框架

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

          <tfoot id='9tbMk'></tfoot>

            <tbody id='9tbMk'></tbody>
          • <bdo id='9tbMk'></bdo><ul id='9tbMk'></ul>

            <small id='9tbMk'></small><noframes id='9tbMk'>

                  本文介绍了如何在 Swift 2 中制作按钮自定义形状的框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我希望该按钮仅在我创建的自定义多边形中而不是在 CGRect 框架中进行点击.

                  I want the button to be reactive to tap only in the custom polygonal shape that I create and not in the CGRect frame.

                  button.frame 只支持 CGRect.

                  button.frame only supports CGRect.

                  推荐答案

                  这是一个仅响应特定区域内的触摸的按钮示例.

                  Here is an example of a button that only responds to touches within a certain area.

                  class MyButton: UIButton {
                  
                      var path: UIBezierPath!
                  
                      override func awakeFromNib() {
                          backgroundColor = UIColor.greenColor()
                          addTarget(self, action: #selector(touchDown), forControlEvents: .TouchDown)
                      }
                      override func drawRect(rect: CGRect) {
                          path = UIBezierPath()
                  
                          path.moveToPoint(CGPointMake(150, 10))
                          path.addLineToPoint(CGPointMake(200, 10))
                          path.addLineToPoint(CGPointMake(150, 100))
                          path.addLineToPoint(CGPointMake(100, 100))
                          path.closePath()
                  
                          let shapeLayer = CAShapeLayer()
                          shapeLayer.strokeColor = UIColor.redColor().CGColor
                          shapeLayer.fillColor = UIColor.blueColor().CGColor
                          shapeLayer.path = path.CGPath
                          layer.addSublayer(shapeLayer)
                  
                      }
                  
                      func touchDown(button: MyButton, event: UIEvent) {
                          if let touch = event.touchesForView(button)?.first {
                              let location = touch.locationInView(button)
                  
                              if path.containsPoint(location) == false {
                                  button.cancelTrackingWithEvent(nil)
                              }
                          }
                  
                      }
                  }
                  

                  这篇关于如何在 Swift 2 中制作按钮自定义形状的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:保持 iPhone UIButton 突出显示 下一篇:如何在导航栏中创建返回按钮

                  相关文章

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

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

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