gpt4 book ai didi

ios - iOS中设置CALayer 'borderWidth'和 'cornerRadius',不能完全覆盖背景

转载 作者:行者123 更新时间:2023-12-01 08:55:46 25 4
gpt4 key购买 nike

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

self.yuanjiao.backgroundColor = [UIColor blackColor];
self.yuanjiao.layer.cornerRadius = self.yuanjiao.frame.size.width/2;
self.yuanjiao.layer.masksToBounds = YES;
self.yuanjiao.layer.borderWidth = 5;
self.yuanjiao.layer.borderColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1].CGColor;

// self.yuanjiao.layer.shadowOffset = CGSizeMake(0, 0);
// self.yuanjiao.layer.shadowRadius = 0.0;
// self.yuanjiao.layer.shadowColor = [UIColor whiteColor].CGColor;
// self.yuanjiao.layer.shadowOpacity = 0.0;
}

效果:

i.stack.imgur.com/alPDr.png

边框没有完全覆盖背景。

设置 shadowxxx 没有效果。

最佳答案

这是图层属性的预期行为。如果你看Apple Documentation对于 borderWidth 属性,您会发现:-

Discussion
When this value is greater than 0.0, the layer draws a border using the current borderColor value. The border is drawn inset from the receiver’s bounds by the value specified in this property. It is composited above the receiver’s contents and sublayers and includes the effects of the cornerRadius property.

The default value of this property is 0.0.

如果您还需要用blackColor填充borderWidth部分,那么您有两种选择

  1. 具有与 View 内容颜色相同的边框是没有意义的。您将根本看不到边界。您将看到的只是一个更大的圆圈,里面充满了 blackColor
  2. 如果您想保留边框并且还需要用黑色填充它,请将 borderColor 属性分配给 blackColor

关于ios - iOS中设置CALayer 'borderWidth'和 'cornerRadius',不能完全覆盖背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31602251/

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