这是我添加到新 View Controller 的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 100)];
[contentView setClipsToBounds:YES];
[contentView setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:contentView];
[[contentView layer] setBorderColor:[[UIColor lightGrayColor] CGColor]];
[[contentView layer] setBorderWidth:1.0f];
[[contentView layer] setCornerRadius:5.0f];
[[contentView layer] setMasksToBounds:YES];
}
结果:
如果看角落,我们可以看到外面的蓝色像素:
Best Answer-推荐答案 strong>
您可以使用 CAShapeLayer :
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 100)];
[self.view addSubview:contentView];
CAShapeLayer *subLayer = [[CAShapeLayer alloc] init];
[subLayer setFillColor:[UIColor blueColor].CGColor];
[subLayer setStrokeColor:[UIColor grayColor].CGColor];
[subLayer setLineWidth:6.0];
[subLayer setPath:[UIBezierPath bezierPathWithRoundedRect:contentView.bounds cornerRadius:5.0].CGPath];
[contentView.layer addSublayer:subLayer];
}
关于ios - 颜色问题外的惊人圆角半径,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/29213208/
|