【问题标题】:How to set corner radius with correct layer border?如何使用正确的图层边界设置角半径?
【发布时间】:2014-01-22 13:37:19
【问题描述】:

我正在创建 uiview 按钮

'Button = [UIButton buttonWithType:UIButtonTypeCustom];

在选定状态和正常状态下具有颜色。 关键是我想改变面具。使我的按钮具有一侧半径角。

为此,我正在使用方法:

- (void)cornerMaskRadiusAtButton:(UIButton*)button leftSide:(BOOL)side
{
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = button.bounds;
    UIBezierPath *roundedPath;
    if(side){
    roundedPath =[UIBezierPath bezierPathWithRoundedRect:maskLayer.bounds
                          byRoundingCorners:UIRectCornerTopLeft |
     UIRectCornerBottomLeft
                                cornerRadii:CGSizeMake(18.f, 18.f)];
    }
    else{
        roundedPath = [UIBezierPath bezierPathWithRoundedRect:maskLayer.bounds
                              byRoundingCorners:UIRectCornerTopRight |
         UIRectCornerBottomRight
                                    cornerRadii:CGSizeMake(18.f, 18.f)];
    }
    maskLayer.path = [roundedPath CGPath];
    button.layer.mask = maskLayer;
}

但是结果是这样的:

在我称之为方法之后:

[self cornerMaskRadiusAtButton:Button leftSide:NO];

Button.layer.borderColor = [UIColor whiteColor].CGColor;
Button.layer.borderWidth = 1.;

但是边框是错误的。

如何修复边界线?

【问题讨论】:

    标签: ios ipad uiview layer mask


    【解决方案1】:

    你不会看到你的图层边框,因为你正在用你的图层蒙版切断它。 这就是为什么你只看到它的一部分而其他没有。他们被剪掉了。

    最好的方法是为按钮创建一个图形并替换 bacgroundimage 例如:

    icon  = [UIImage imageNamed:@"name"];
    [Button setBackgroundImage:icon  forState:UIControlStateNormal];
    

    U 可以设置为喜欢的其他状态:UIControlStateSelected 其他图片。

    【讨论】:

      猜你喜欢
      • 2020-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-09
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      相关资源
      最近更新 更多