简体   繁体   中英

How can i make a wave border of a uiview?

i want to make the border of a UIView to be like a wave and i just can't get it out how. I have tried just to draw a wave line with a code found here, but it just don't work

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);

try like this:

- (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)];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM