gpt4 book ai didi

ios - 颜色问题外的惊人角半径

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:00:59 24 4
gpt4 key购买 nike

这是我添加到新 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];
}

结果:

enter image description here

如果观察角落,我们可以看到外面的蓝色像素:

enter image description here

最佳答案

你可以使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com