开发者社区 问答 正文

如果定义一个只有上边圆角的UIButton

一般button都是带着四个圆角的
如果定义只有上面的那条边,即只有左上和右上是圆角的button , 其他两个是直角

展开
收起
a123456678 2016-07-20 17:33:47 1860 分享 版权
1 条回答
写回答
取消 提交回答
  • UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(120, 10, 80, 80)];
    view2.backgroundColor = [UIColor redColor];
    [self.view addSubview:view2];

    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = view2.bounds;
    maskLayer.path = maskPath.CGPath;
    view2.layer.mask = maskLayer;

    2019-07-17 19:59:06
    赞同 展开评论
问答地址: