iOS中UIView半邊圓角設定
阿新 • • 發佈:2019-01-25
- (UIButton *)addButton { if (!_addButton) { self.addButton = [UIButton buttonWithType:UIButtonTypeCustom]; _addButton.frame = CGRectMake(maxX(self.contentTextFiled), minY(self.contentTextFiled), BUTTONWIDTH*KScDefineWidth, BUTTONWIDTH*KScDefineWidth); //TODO:uiview 單邊圓角或者單邊框 UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_addButton.bounds byRoundingCorners:(UIRectCornerTopRight | UIRectCornerBottomRight) cornerRadii:CGSizeMake(5,5)];//圓角大小 CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = _addButton.bounds; maskLayer.path = maskPath.CGPath; _addButton.layer.mask = maskLayer; [_addButton setBackgroundImage:[UIImage imageNamed:@"img_add_black"] forState:UIControlStateNormal]; [_addButton addTarget:self action:@selector(addNumAction:) forControlEvents:UIControlEventTouchUpInside]; } return _addButton; }