美文网首页
view设置圆角

view设置圆角

作者: 筱笑 | 来源:发表于2017-04-06 16:13 被阅读32次
  • view的四个角都具有一定弧度
UIView * footView = [[UIView alloc]initWithFrame:CGRectMake(10, 40, 300, 400)];
footView.backgroundColor = [UIColor redColor];
footView.userInteractionEnabled = YES;
[footView.layer setCornerRadius:5];  //弧度大小
footView.layer.masksToBounds = YES;
footView.contentMode = UIViewContentModeScaleAspectFill;
[self.view addSubview:footView];
  • view的某个角为具有一定弧度
 // 设置某个角为圆角
/*
     UIRectCornerTopLeft------左上角
     UIRectCornerTopRight-----右上角
     UIRectCornerBottomLeft---左下角
     UIRectCornerBottomRight--右下角
*/
UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(10, 40, 300, 400)];
bgView.backgroundColor = [UIColor redColor];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:bgView.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(5, 5)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = bgView.bounds;
maskLayer.path = maskPath.CGPath;
bgView.layer.mask = maskLayer;
[self.view addSubview:bgView];

相关文章

网友评论

      本文标题:view设置圆角

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