gpt4 book ai didi

ios - UIBezierPath 简单矩形

转载 作者:可可西里 更新时间:2023-11-01 03:29:38 25 4
gpt4 key购买 nike

我只想使用以下函数在 View 中绘制一个简单的矩形:

- (void)drawRect:(CGRect)rect {
[super drawRect:rect];
if (self.drawTextBouble) {
[[UIColor blueColor] setFill];
UIBezierPath *aPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(40, 0, 230, 120) cornerRadius:12.0];
[aPath fill];
}
}

上面的代码用纯黑色背景填充 View ,矩形之外是不透明的。我该如何解决这个问题?

编辑:

下面的解决方案有效,但这也有效:

[self setOpaque:NO];

最佳答案

你的绘图代码没问题。如果想让自定义绘制的view有透明背景,只需要设置

self.backgroundColor = [UIColor clearColor];

在 View 的 - (id)initWithFrame:(CGRect)frame

编辑:关于调用 [super drawRect:rect] 的一点注意事项。 UIView 文档说:

If you subclass UIView directly, your implementation of this method does not need to call super. However, if you are subclassing a different view class, you should call super at some point in your implementation.

关于ios - UIBezierPath 简单矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17162263/

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