任意上下左右的圆角

来源:互联网 发布:日事清 mac 编辑:程序博客网 时间:2024/06/01 15:24
UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(120, 10, 80, 80)];view2.backgroundColor = [UIColor redColor];[self.view addSubview:view2];    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view2.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];maskLayer.frame = view2.bounds;maskLayer.path = maskPath.CGPath;view2.layer.mask = maskLayer;
这种方法是有效的,但是注意在cell里面的话,要放在drawrect方法里面,layoutsubview和init方法里面都拿不到正确的frame.
原创粉丝点击