gpt4 book ai didi

ios - 如何制作 uiview 的波浪边框?

转载 作者:行者123 更新时间:2023-11-29 02:52:54 27 4
gpt4 key购买 nike

我想让 UIView 的边框像波浪一样,但我就是不知道怎么做。我试过用这里找到的代码画一条波浪线,但它不起作用

CGRect rect = CGRectMake(100, 100, 500, 500);

self.heightCrest = 30;
float w = 0; // starting position
float y = rect.size.height;
float width = rect.size.width;
int cycles = 7;//number of waves
self.x = width/cycles;
CGContextRef context = UIGraphicsGetCurrentContext();
CGMutablePathRef path = CGPathCreateMutable();
while (w<width) {
CGPathMoveToPoint(path, NULL, w,y/2);
CGPathAddQuadCurveToPoint(path, NULL, w+self.x/4, y/2 - self.heightCrest, w+self.x/2, y/2);
CGPathAddQuadCurveToPoint(path, NULL, w+3*self.x/4, y/2 + self.heightCrest, w+self.x, y/2);
w+=self.x;
}
CGContextAddPath(context, path);
CGContextDrawPath(context, kCGPathStroke);

最佳答案

像这样尝试:

- (void)addHorizontalDownwardCurveToPath:(UIBezierPath *)path toPoint:(CGPoint)point withAmplitude:(CGFloat)amplitude {
CGFloat middle = (point.x + path.currentPoint.x) / 2;
[path addQuadCurveToPoint:point
controlPoint:CGPointMake(middle, point.y + amplitude)];
}

关于ios - 如何制作 uiview 的波浪边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24280382/

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