我用的是Masonry布局.
我想绘制如箭头所示的部分圆角按钮.请问用代码怎么实现?
在哪个方法里面写?
code:
//部分圆角按钮
UIButton *loggedBtn = [[UIButton alloc]init];
loggedBtn.backgroundColor = [UIColor blueColor];
[headView addSubview:loggedBtn];
[loggedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.offset(40);
make.height.offset(20);
make.right.equalTo(headView);
make.centerY.equalTo(headView);
}];
我直接把我代码给你,你看一下应该就知道怎么修改我的代码实现你要的效果啦
- (void)setupCornerRadius
{
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.musicChooseView.bounds
byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
cornerRadii:CGSizeMake(12, 12)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.musicChooseView.bounds;
maskLayer.path = maskPath.CGPath;
self.musicChooseView.layer.mask = maskLayer;
}
直接找一张,部分圆角的图片不就可以了?
可以程序员改,不过我觉得最简单的方式是让美工直接提供就好了。没必要在这个问题上折腾程序员,嘿嘿
修改button的layer就可以了。改为你想要的圆角,再加上背景颜色。layer里面有这些API,你可以看一下。
//部分圆角按钮
UIButton *loggedBtn = [[UIButton alloc]init];
loggedBtn.backgroundColor = [UIColor blueColor];
loggedBtn.layer.cornerRadius = 10;
UIEdgeInsets padding = UIEdgeInsetsMake(10, 10, 10, 10);
[self.view addSubview:loggedBtn];
[loggedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.offset(80);
make.height.offset(20);
make.right.equalTo(self.view.mas_right).with.offset(padding.right);
make.centerY.equalTo(self.view);
}];