<small id='7l6EF'></small><noframes id='7l6EF'>

      1. <tfoot id='7l6EF'></tfoot>
      2. <legend id='7l6EF'><style id='7l6EF'><dir id='7l6EF'><q id='7l6EF'></q></dir></style></legend>
        • <bdo id='7l6EF'></bdo><ul id='7l6EF'></ul>

        <i id='7l6EF'><tr id='7l6EF'><dt id='7l6EF'><q id='7l6EF'><span id='7l6EF'><b id='7l6EF'><form id='7l6EF'><ins id='7l6EF'></ins><ul id='7l6EF'></ul><sub id='7l6EF'></sub></form><legend id='7l6EF'></legend><bdo id='7l6EF'><pre id='7l6EF'><center id='7l6EF'></center></pre></bdo></b><th id='7l6EF'></th></span></q></dt></tr></i><div id='7l6EF'><tfoot id='7l6EF'></tfoot><dl id='7l6EF'><fieldset id='7l6EF'></fieldset></dl></div>
      3. 不使用图像的自定义 UIButton 形状

        Custom UIButton Shape without using an image(不使用图像的自定义 UIButton 形状)
          <bdo id='ZB9CM'></bdo><ul id='ZB9CM'></ul>
            <tbody id='ZB9CM'></tbody>

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

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

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

                  本文介绍了不使用图像的自定义 UIButton 形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想制作一个看起来类似于 UIBackBarButtonItem 的 UIButton(箭头指向左侧的导航堆栈.如果可能的话,我宁愿这样做而不必使用图像,因为按钮的大小会有所不同,具体取决于在手机的方向上.

                  I want to make a UIButton with that looks similar to the UIBackBarButtonItem (with an arrow pointing left for the navigation stack. I would prefer to do this without having to use an image if possible because the button will have a different size depending on the phone's orientation.

                  有没有办法在代码中激活这种影响?我的想法是以某种方式使用按钮的 CALayer.

                  Is there a way to active this affect in code? My idea was using the CALayer of the button somehow.

                  谢谢!

                  编辑

                  我正在尝试使用@Deepak 的建议,但遇到了问题.我希望按钮的右侧看起来像 [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:4] 左侧看起来像箭头.我尝试使用 addQuadCurveToPoint:controlPoint 方法来做到这一点.

                  I am trying to use @Deepak's advice, but I am running into a a problem. I want the right side of the button to look like a [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:4] with the left side looking like an arrow. I tried to do this using the addQuadCurveToPoint:controlPoint method.

                  我使用矩形的角作为控制点,但路径没有像我预期的那样弯曲.它仍然像我只使用 addLineToPoint: 方法一样走投无路.我的代码如下.

                  I am using the corner of the rect as the control point, but the path does not curve like I expect. It is still cornered as if I only used the addLineToPoint: method. My code is below.

                  float radius = 4.0;
                  UIBezierPath *path = [UIBezierPath bezierPath];
                  
                  CGPoint startPoint = CGPointMake(rect.size.width/5.0, 0);
                  CGPoint pointBeforeTopCurve = CGPointMake(rect.size.width - radius, 0);
                  CGPoint topRightCorner = CGPointMake(rect.size.width, 0);
                  CGPoint pointAfterTopCurve = CGPointMake(rect.size.width, 0.0-radius);
                  
                  CGPoint pointBeforeBottomCurve = CGPointMake(rect.size.width, rect.size.height-radius);
                  CGPoint bottomRightCorner = CGPointMake(rect.size.width, rect.size.height);
                  CGPoint pointAfterBottomCurve = CGPointMake(rect.size.width - radius, rect.size.height);
                  
                  CGPoint pointBeforeArrow = CGPointMake(rect.size.width/5.0, rect.size.height);
                  CGPoint arrowPoint = CGPointMake(0, rect.size.height/2.0);
                  
                  
                  [path moveToPoint:pointBeforeTopCurve];
                  [path addQuadCurveToPoint:pointAfterTopCurve controlPoint:topRightCorner];
                  
                  [path addLineToPoint:pointBeforeBottomCurve];
                  [path addQuadCurveToPoint:pointAfterBottomCurve controlPoint:bottomRightCorner];
                  
                  
                  [path addLineToPoint:pointBeforeArrow];
                  [path addLineToPoint:arrowPoint];
                  [path addLineToPoint:startPoint];
                  

                  推荐答案

                  你可以用 Quartz.您将需要子类 UIButton 并实现其 drawRect: 方法.您将必须定义一个路径并用渐变填充它.

                  You can do this with Quartz. You will need subclass UIButton and implement its drawRect: method. You will have to define a path and fill it with a gradient.

                  您还必须实现 hitTest:withEvent:,因为它涉及非矩形形状.

                  You will also have to implement hitTest:withEvent: as it involves non-rectangular shape.

                  这篇关于不使用图像的自定义 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 标题颜色?)
                  Minimum sensible button size on iPhone(iPhone 上的最小合理按钮大小)
                  iPhone UIButton - image position(iPhone UIButton - 图像位置)
                      <tbody id='UeYRb'></tbody>

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

                        <tfoot id='UeYRb'></tfoot>

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

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