2014-06-18 67 views
0

我想讓一個UIView的邊框像波浪一樣,我只是無法弄清楚如何。 我曾嘗試只是爲了繪製這裏找到的代碼的波浪線,但它只是不工作我如何製作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); 
+0

這可能有助於http://ronnqvi.st /思維般的-A-貝塞爾路徑/ – iphonic

回答

1

嘗試這樣的:

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