奇葩-UIButton左上角和右上角圆角

代码收集

//设置view左上角、右上角的为圆角
    UIButton *exclusiveButton = [UIButton buttonWithType:UIButtonTypeCustom];
    exclusiveButton.frame = CGRectMake(200, 200, 100, 100);
    exclusiveButton.backgroundColor = [UIColor lightGrayColor];
    [exclusiveButton setTitle:@"专属客户" forState:0];
    exclusiveButton.tag = 1;
    [self.view addSubview:exclusiveButton];
    //设置圆角
    UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:exclusiveButton.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerTopLeft cornerRadii:CGSizeMake(15, 15)];
    CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
    maskLayer1.frame = exclusiveButton.bounds;
    maskLayer1.path = maskPath1.CGPath;
    exclusiveButton.layer.mask = maskLayer1;

效果

奇葩-UIButton左上角和右上角圆角_第1张图片
Snip20161227_6.png

你可能感兴趣的:(奇葩-UIButton左上角和右上角圆角)