当前位置: 首页 > 工具软件 > Rounded View > 使用案例 >

ios view 切上部分圆角_iOS开发-View切圆角

范文昌
2023-12-01

//OC对应的系统和自定义切圆角

///默认切四个角的圆角

// v.clipsToBounds = YES;

// v.layer.cornerRadius = 8;

//自定义切多个角圆角

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:v.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(8, 8)];

CAShapeLayer *maskLayer = [CAShapeLayer new];

maskLayer.frame = v.bounds;

maskLayer.path = maskPath.CGPath;

v.layer.mask = maskLayer;

//Swift对应的系统和自定义切圆角

let v = UIView.init(frame: CGRect.init(x: 100, y: 100, width: 100, height: 100));

v.backgroundColor = UIColor.cyan;

v.layer.masksToBounds = true;

v.layer.cornerRadius = 8;

self.view.addSubview(v);

let v2 = UIView.init(frame: CGRect.init(x: 300, y: 100, width: 100, height: 100));

v2.backgroundColor = UIColor.red;

self.view.addSubview(v2);

let maskpath = UIBezierPath.init(roundedRect: v2.bounds, byRoundingCorners:[.bottomLeft , .topLeft , .bottomRight], cornerRadii: CGSize.init(width: 4, height: 4))

let maskLayer = CAShapeLayer.init()

maskLayer.frame = v2.bounds;

maskLayer.path = maskpath.cgPath;

v2.layer.mask = maskLayer

 类似资料: