Quartz2D

//画线

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextMoveToPoint(context, 100.f,100.f);

    CGContextAddLineToPoint(context, 200.f, 200.f);

    CGContextStrokePath(context);

//画折线

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGPoint lines[] =

    {

       CGPointMake(100.f,100.f),

       CGPointMake(200.f,30.f),

       CGPointMake(40.f,150.f),

       CGPointMake(70.f,400.f),

       CGPointMake(10.f,100.f),

       CGPointMake(100.f,10.f),

       CGPointMake(100.f,100.f),

    };

    CGContextAddLines(context, lines, sizeof(lines)/sizeof(lines[0]));

    CGContextStrokePath(context);

//画平行线(两个点一组,画多条线段)

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGPoint lines[] =

    {

       CGPointMake(10.f,200.f),

       CGPointMake(50.f,100.f),

       CGPointMake(90.f,200.f),

       CGPointMake(130.f,100.f),

       CGPointMake(170.f,200.f),

       CGPointMake(210.f,100.f),

    };

    CGContextAddLines(context, lines, sizeof(lines)/sizeof(lines[0]));

    CGContextStrokeLineSegments(context, lines, sizeof(lines)/sizeof(lines[0]));

    CGContextStrokePath(context);

//画矩形

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextAddRect(context, CGRectMake(20, 20, 100, 300));

    CGContextStrokePath(context);

//画多个矩形(可以话表格)

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextAddRect(context, CGRectMake(20, 20, 100, 300));

    CGRect rects[] = {

       CGRectMake(20,20, 30, 30),

       CGRectMake(40,20, 30, 30),

       CGRectMake(20,70, 20, 30),

       CGRectMake(80,20, 30, 10),

       CGRectMake(200,20, 70, 30),

    };

    CGContextAddRects(context, rects, sizeof(rects)/sizeof(rects[0]));

    CGContextStrokePath(context);

//画圆

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextAddEllipseInRect(context, CGRectMake(30, 30, 60, 30));

    CGContextStrokePath(context);

//画实心圆

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextBeginPath(context);

    CGRect circle = CGRectInset(self.bounds, 50, 50);

    CGContextAddEllipseInRect(context, circle);

    CGContextFillPath(context);

//画扇形

    CGContextRef context = UIGraphicsGetCurrentContext();

   //设置圆心点(不写为半弧形)

    CGContextMoveToPoint(context, 130, 130);

   //设置属性(扇形)扇形圆心坐标 XY 半径 起点角度 终点角度 画取方向(0=逆时针,1=顺时针)

    CGContextAddArc(context, 130,130, 70.f,-270, 180,1);

   //闭合

    CGContextClosePath(context);

   //实心

    CGContextFillPath(context);

   //空心

    CGContextStrokePath(context);

    //清除区域

    CGContextClearRect(context, CGRectMake(100,100, 80, 50));

//画渐变色

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGColorSpaceRef color = CGColorSpaceCreateDeviceRGB();

    UIColor *startColor = [UIColorblueColor];

    CGFloat *startColorComp = (CGFloat *)CGColorGetComponents(startColor.CGColor);

    UIColor *endColor = [UIColoryellowColor];

    CGFloat *endColorComp = (CGFloat*)CGColorGetComponents(endColor.CGColor);

    CGFloat colorComponents[8]= {

       startColorComp[0],

       startColorComp[1],

       startColorComp[2],

       startColorComp[3],

       endColorComp[0],

       endColorComp[1],

       endColorComp[2],

       endColorComp[3]

    };

    CGFloat colorIndices[2]= {

       0.f,

       1.f

    };

    CGGradientRef gradient = CGGradientCreateWithColorComponents(color,colorComponents, colorIndices, 2);

    CGContextDrawLinearGradient(context, gradient, CGPointMake(120,260), CGPointMake(200, 230), 0);

//设置阴影

CGContextSetShadow(context, CGSizeMake(20, 20), 20);

//绘位图

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextDrawImage(context, CGRectMake(100,100, 200,300), [UIImageimageNamed:@"096.jpg"].CGImage);

//绘字

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGFontRef font = CGFontCreateWithFontName((CFStringRef)@"Helvetica");

    CGContextSetFont(context, font);

    CGContextSetFontSize(context, 100.f);

    CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0, -1.0));

    CGPoint points[] = {

       CGPointMake(150.f,-200.f)

    };

    CGGlyph glays[1]= {90};

    CGContextShowGlyphsAtPositions(context, glays,points,3);

    self.layer.shouldRasterize = YES;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值