gpt4 book ai didi

ios - 创建一个复杂的 CGRect

转载 作者:行者123 更新时间:2023-11-28 23:01:56 25 4
gpt4 key购买 nike

我有一个在方法上绘制了 10 像素边框的 View 。我需要更新边框颜色并使用 [self setNeedsDisplay] 使其重绘风景。因为我只需要更新我想使用的边框:[self setNeedsDisplayInRect:rect] 所以它只会绘制边框。

如何在 View 的其他区域中只获得边框的矩形?

谢谢沙尼

最佳答案

你不能,因为 CGRect 是矩形,所以它是一个不能有洞的凸形。

但是您可以将边框分解为四个矩形并调用 [self setNeedsDisplayInRect:rect] 四次。

此外,如果您导入 QuartzCore,您可能可以使用 View 层的属性 borderColor:

#import <QuartzCore/QuartzCore.h>

// ...

view.layer.borderWidth = 10;
view.layer.borderColor = [UIColor redColor].CGColor;

// And to change it later
view.layer.borderColor = [UIColor greenColor].CGColor;

关于ios - 创建一个复杂的 CGRect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9852361/

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