美文网首页iOS技术
UIButton切圆角

UIButton切圆角

作者: 旭日飞扬 | 来源:发表于2018-07-23 11:32 被阅读11次

UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 200, 60)];
button.center = self.view.center;
button.backgroundColor = [UIColor blueColor];
[button setTitle:@"世界那么大" forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
CGRect rect = button.bounds;
//所切圆角尺寸
CGSize radio = CGSizeMake(30, 30);
//可以自己设置所切的圆角
UIRectCorner corner = UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomLeft;
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corner cornerRadii:radio];
CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];
masklayer.frame = button.bounds;
masklayer.path = path.CGPath;
button.layer.mask = masklayer;

相关文章

网友评论

    本文标题:UIButton切圆角

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