画多边形,填充颜色。

- (void)drawRect:(CGRect)rect {

    

    CGContextRef ctx = UIGraphicsGetCurrentContext();

    CGContextBeginPath(ctx);

    

    float x = 0;

    float y = 0;

    float w = rect.size.width;

    float h = rect.size.height;

    ///四个点。

    UIBezierPath *movePath = [UIBezierPathbezierPath];

    CGPoint point1 = CGPointMake(x, h/2);

    CGPoint point2 = CGPointMake(w/2, h);

    CGPoint point3 = CGPointMake(w, h/2);

    CGPoint point4 = CGPointMake(w/2, y);

    

    ///1---2.

    [movePath moveToPoint:point1];

    [movePath addQuadCurveToPoint:point2

                     controlPoint:CGPointMake((point1.x + point2.x)/4,(point1.y + point2.y)/2)];

    

     ///2---3.

    [movePath addQuadCurveToPoint:point3

                     controlPoint:CGPointMake((point2.x + point3.x)/2,(point2.y + point3.y)/1.5)];

     ///3---4.

    [movePath addQuadCurveToPoint:point4

                     controlPoint:CGPointMake(w/4*3,h/20)];

 

     ///4---1.

    [movePath addQuadCurveToPoint:point1

                     controlPoint:CGPointMake(w/4,h/20)];

    

//    ///线的宽度和颜色。

    movePath.lineWidth = 1;

    CGContextAddPath(ctx, movePath.CGPath);

    CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);

    CGContextFillPath(ctx);

    CGContextClosePath(ctx);

    CGContextClip(ctx);

    

    [selfsetNeedsDisplay];

}

 

 

调用的时候: self.myView.frame = tempR;,一改frame就自动执行了。

猜你喜欢

转载自zhangmingwei.iteye.com/blog/2164728