1. 程式人生 > >設定UIView幾個角為圓角

設定UIView幾個角為圓角

UIButton *btn = [[UIButtonalloc] initWithFrame:CGRectMake(PhaseHalf(CGRectGetWidth(self.view.bounds),kWidth), PhaseHalf(CGRectGetHeight(self.view.bounds),kWidth), kWidth, kWidth)];

    [btn setBackgroundColor:[UIColorredColor]];

    [self.view addSubview:btn];

    [btn addTarget:selfaction:@selector

(onBtnTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];

UIBezierPath *maskPath = [UIBezierPathbezierPathWithRoundedRect:btn.boundsbyRoundingCorners:UIRectCornerBottomLeft| UIRectCornerBottomRightcornerRadii:CGSizeMake(10.0, 10.0)];

CAShapeLayer *maskLayer = [CAShapeLayerlayer];

    maskLayer.frame

= btn.bounds;

    maskLayer.path = maskPath.CGPath;

    btn.layer.mask = maskLayer;