CG

 

//设置线的宽度

CGContextSetLineWidth(ctx, 12);

//设置线的连接处 (拐点)

 CGContextSetLineJoin(ctx, kCGLineJoinRound )

/* Line join styles. */

      enum CGLineJoin {

        kCGLineJoinMiter,

        kCGLineJoinRound,//圆滑的

        kCGLineJoinBevel

    };

   

 

//设置线的端点

CGContextSetLineCap(ctx, kCGLineCapButt); 设置 线的端点样式

enum CGLineCap {

    kCGLineCapButt,//和第三个一样 。。。。不懂

    kCGLineCapRound,//端点是圆的

    kCGLineCapSquare //正方形

};

typedef enum CGLineCap CGLineCap;

 

//以渐变色填充当前的线

 

    //list of components

    CGFloat components[8] = {

        0.0, 0.0, 1.0, 1.0,     // Start color - Blue

        1.0, 0.0, 1.0, 1.0 };   // End color - Violet

    

    CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB();

    CGGradientRef gradient = CGGradientCreateWithColorComponents(baseSpace, components, NULL, 2);

    CGColorSpaceRelease(baseSpace), baseSpace = NULL;

    

    //Gradient direction

    CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect));

    CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect));

    

    //Draw the gradient

    CGContextDrawLinearGradient(ctx, gradient, startPoint, endPoint, 0);

    CGGradientRelease(gradient), gradient = NULL;

    

    CGContextRestoreGState(ctx);

posted @ 2013-07-25 17:18  zander  阅读(420)  评论(0编辑  收藏  举报