gpt4 book ai didi

iphone - 在drawRect中绘制形状会删除渐变

转载 作者:行者123 更新时间:2023-11-29 04:06:44 24 4
gpt4 key购买 nike

我对核心显卡非常陌生。

基本上,我有一个绘制渐变背景的 View ,我尝试使用另一个 View 创建该 View 的子类,然后在该子类中绘制三角形。

发生的情况是渐变没有被绘制。我怀疑是因为我的子类在drawRect中绘制了一个三角形( super 类在其中绘制了渐变),所以我的子类覆盖了drawRect方法并且 super 类被忽略了。

如何同时绘制渐变和三角形?

这是我的子类的drawRect的代码

- (void)drawRect:(CGRect)rect
{
// get the current content
CGContextRef context = UIGraphicsGetCurrentContext();

CGFloat buttonHeight = self.bounds.size.height;
CGFloat buttonWidth = self.bounds.size.width;

// draw triangle
UIBezierPath *path = [UIBezierPath bezierPath];

[path moveToPoint:CGPointMake(buttonWidth / 2, buttonHeight * .75)];
[path addLineToPoint:CGPointMake(buttonWidth * .75, buttonHeight * .25)];
[path addLineToPoint:CGPointMake(buttonWidth * .25,buttonHeight * .25)];

CGContextAddPath(context, path.CGPath);
CGContextClip(context);
[_arrowColor set];
[path fill];
}

最佳答案

如果你在子类'drawRect:的开头调用[super drawRect:rect];,那么它将首先绘制渐变,然后绘制三角形。

关于iphone - 在drawRect中绘制形状会删除渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15076259/

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