美文网首页
button的圆角设置

button的圆角设置

作者: 克拉克定律 | 来源:发表于2017-03-31 18:28 被阅读48次

设置button的圆角时可以选者指定4个角中的一个角,设置成圆角,可以用来实现如下的效果

804A353A-5428-4F72-AC2F-B04CF8CEFB48.png

设置左上角和左下角为圆角

 UIBezierPath *leftPath = [UIBezierPath bezierPathWithRoundedRect:self.midOneBtn.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:CGSizeMake(TRANS_VALUE2(10.0f), TRANS_VALUE2(10.0f))];
 CAShapeLayer *leftLayer = [[CAShapeLayer alloc] init];
 leftLayer.frame = self.midOneBtn.bounds;
 leftLayer.path = leftPath.CGPath;
 self.midOneBtn.layer.mask = leftLayer;

指定哪个角为圆角的UIRectCorner

typedef NS_OPTIONS(NSUInteger, UIRectCorner) {
    UIRectCornerTopLeft     = 1 << 0,
    UIRectCornerTopRight    = 1 << 1,
    UIRectCornerBottomLeft  = 1 << 2,
    UIRectCornerBottomRight = 1 << 3,
    UIRectCornerAllCorners  = ~0UL
};

图中的实现具体代码
.h

@property (nonatomic, strong) UIButton * midOneBtn; //自提
@property (nonatomic, strong) UIButton * midTwoBtn; //配送

.m

    self.midOneBtn = [[UIButton alloc] init];
    self.midOneBtn.frame = CGRectMake(TRANS_VALUE2(27.0f), TRANS_VALUE2(188.0f), TRANS_VALUE2(160.5f), TRANS_VALUE2(38.0f));
    [self.midOneBtn setTitle:@"自提" forState:UIControlStateNormal];
    [self.midOneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.midOneBtn.backgroundColor = [UIColor redColor];
    [self.midOneBtn addTarget:self action:@selector(midOneAction) forControlEvents:UIControlEventTouchDown];
    [self.backView addSubview:self.midOneBtn];
    
    UIBezierPath *leftPath = [UIBezierPath bezierPathWithRoundedRect:self.midOneBtn.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:CGSizeMake(TRANS_VALUE2(10.0f), TRANS_VALUE2(10.0f))];
    CAShapeLayer *leftLayer = [[CAShapeLayer alloc] init];
    leftLayer.frame = self.midOneBtn.bounds;
    leftLayer.path = leftPath.CGPath;
    self.midOneBtn.layer.mask = leftLayer;
    
    self.midTwoBtn = [[UIButton alloc] init];
    self.midTwoBtn.frame = CGRectMake(TRANS_VALUE2(187.5f), TRANS_VALUE2(188.0f), TRANS_VALUE2(160.0f), TRANS_VALUE2(38.0f));
    [self.midTwoBtn setTitle:@"配送" forState:UIControlStateNormal];
    [self.midTwoBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    self.midTwoBtn.backgroundColor = [UIColor whiteColor];
    [self.midTwoBtn addTarget:self action:@selector(midTwoBtnAction) forControlEvents:UIControlEventTouchDown];
    [self.backView addSubview:self.midTwoBtn];
    
    UIBezierPath *rightPath = [UIBezierPath bezierPathWithRoundedRect:self.midTwoBtn.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii:CGSizeMake(TRANS_VALUE2(10.0f), TRANS_VALUE2(10.0f))];
    CAShapeLayer *rightLayer = [[CAShapeLayer alloc] init];
    rightLayer.frame = self.midTwoBtn.bounds;
    rightLayer.path = rightPath.CGPath;
    self.midTwoBtn.layer.mask = rightLayer;

相关文章

  • UIButton

    设置按钮 左对齐、 居中、 右对齐 设置button 圆角 当tableview(collectionView )...

  • QQ粘性布局

    按钮button自定义button设置圆角半径cornerRadius取消高亮状态重写setHighlighted...

  • iOS之storyBoard相关-在storyBoard上给UI

    以button为例,在storyBoard上给button设置圆角(1).新建一个button.xib (2).给...

  • button的圆角设置

    设置button的圆角时可以选者指定4个角中的一个角,设置成圆角,可以用来实现如下的效果 设置左上角和左下角为圆角...

  • xib中设置按钮的边框颜色

    首先,说一下如何在xib中设置Button的边框及圆角效果: 选中要设置的Button, 切换到图中对应位置,点击...

  • Xcode 设置按钮的边框颜色

    首先,说一下如何在xib中设置Button的边框及圆角效果:选中要设置的Button, 切换到图中对应位置,点击加...

  • button圆角高效设置

    需求我们会经常遇到这样一个需求,给TableViewCell添加标签,例如:饿了么App中店铺会有,减、特、新等标...

  • xib设置button圆角

    http://www.jianshu.com/p/6bfdfe3867cb

  • Button属性maskedCorners

    在iOS 11之前设置button的圆角,使用的方法如下 iOS 11之后button新增了一个属性 m...

  • xib设置button的圆角

    http://www.jianshu.com/p/3f6a4343139e

网友评论

      本文标题:button的圆角设置

      本文链接:https://www.haomeiwen.com/subject/fbbvottx.html