iOS 设置视图的圆角效果

来源:互联网 发布:神创天下骑兵升级数据 编辑:程序博客网 时间:2024/05/16 20:33
- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(50, 100, 100, 100)];
    view.backgroundColor = [UIColor cyanColor];

    [self.view addSubview:view];
    
//    (UIRectCorner)corners
//    UIRectCornerTopLeft     = 1 << 0,
//    UIRectCornerTopRight    = 1 << 1,
//    UIRectCornerBottomLeft  = 1 << 2,
//    UIRectCornerBottomRight = 1 << 3,
//    UIRectCornerAllCorners  = ~0UL
//    设置指定角的有圆角效果

    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(20, 20)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = view.bounds;
//    maskLayer.masksToBounds = YES;
    maskLayer.borderColor = [UIColor blackColor].CGColor;
    maskLayer.path = maskPath.CGPath;
    view.layer.mask = maskLayer;
    // Do any additional setup after loading the view, typically from a nib.
}
0 0
原创粉丝点击