Xcode Quartz 2D 繪圖

//繪圖  繼承與UIViewspa

- (void)drawRect:(CGRect)rect
3d


{orm

    //繪製圖片繼承

    [self drawImage];圖片

    //繪製文本ip

    [self drawText];it

    //繪製線io

    [self drawLine];im

    

    //矩形樣式

    [self drawRecttang];

    [self drawArc];

    

}


//弧線

-(void)drawArc{

    //獲得上下文

    CGContextRef ref = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(ref, [UIColor redColor].CGColor);

    CGContextMoveToPoint(ref, 150, 150);

    //參數   圓心  半徑  順時針逆時針

    //餅型圖自定義

    //所佔的比例能夠自定義

    CGContextAddArc(ref, 150, 150, 100, 0, 100*M_PI /180, 0);

    CGContextFillPath(ref);

    

    CGContextSetFillColorWithColor(ref, [UIColor blueColor].CGColor);

    CGContextMoveToPoint(ref, 150, 150);

    CGContextAddArc(ref, 150, 150, 100, 100*M_PI /180, 260*M_PI /180, 0);

    CGContextFillPath(ref);

    

    CGContextSetFillColorWithColor(ref, [UIColor yellowColor].CGColor);

    CGContextMoveToPoint(ref, 150, 150);

    CGContextAddArc(ref, 150, 150,100 , 260*M_PI /180, 360*M_PI /180, 0);

    CGContextFillPath(ref);

    

    //拋物線

    CGContextMoveToPoint(ref, 50, 200);

    CGContextAddQuadCurveToPoint(ref, 100, 400, 150, 200);

    CGContextStrokePath(ref);

    //Core Graphics/OpenGL ES  繪圖系統

}


//矩形

-(void)drawRecttang{

    

//獲得上下文

    CGContextRef ref = UIGraphicsGetCurrentContext();

    //<#CGFloat blur#> 最後一個參數表明的是陰影的羽化程度

    //CGContextSetShadow(ref, CGSizeMake(30, 30), 20);

    CGContextSetShadowWithColor(ref, CGSizeMake(30, 30), 20, [UIColor yellowColor].CGColor);

    

    //填充顏色

    CGContextSetFillColorWithColor(ref, [UIColor magentaColor].CGColor);

    //矩形

    CGContextAddRect(ref, CGRectMake(50, 50, 200, 200));

    CGContextAddEllipseInRect(ref, CGRectMake(50, 50, 200, 200));

    

    //只是劃線  不能與填充先後執行  執行完前面的以後  命令就中止繪圖

    //CGContextStrokePath(ref);

    

    //填充

    //CGContextFillPath(ref);

    

    //同時劃線填充

    CGContextDrawPath(ref, kCGPathFillStroke);

}


//

-(void)drawLine{

    //獲得上下文

    CGContextRef ref = UIGraphicsGetCurrentContext();

    //線的顏色

    CGContextSetStrokeColorWithColor(ref, [UIColor magentaColor].CGColor);

    //線寬

    CGContextSetLineWidth(ref, 10);

    //相交時角的樣式

    CGContextSetLineJoin(ref, kCGLineJoinRound);

    //畫虛線 10 是起始位置

    CGFloat lengths[] = {20,20};//實線 虛線 20  10

    CGContextSetLineDash(ref, 10  , lengths, 2);

    //虛線的地方是圓角

    CGContextSetLineCap(ref, kCGLineCapRound);

    //移動起點  畫筆的起點

    CGContextMoveToPoint(ref, 50, 50);

    //添加一條線

    CGContextAddLineToPoint(ref, 250, 50);

    CGContextAddLineToPoint(ref, 150, 250);

    //CGContextAddLineToPoint(ref, 50, 50);

    //封閉圖形

    CGContextClosePath(ref);

    //開始劃線

    CGContextStrokePath(ref);

    

    

}


//文本


-(void)drawText{

    NSString * str = @"西門吹雪大戰葉孤城,陸小鳳,花滿樓,司空摘星,木道人。";

    [str drawInRect:self.bounds withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:30.0],NSForegroundColorAttributeName:[UIColor blueColor]}];

}


//圖片

-(void)drawImage{

    UIImage * image1 = [UIImage imageNamed:@"5"];

    [image1 drawInRect:self.bounds];

    

    UIImage * image2 = [UIImage imageNamed:@"32_16"];

    //疊加效果

    /*

     kCGBlendModeNormal,

     kCGBlendModeMultiply,

     kCGBlendModeScreen,

     kCGBlendModeOverlay,

     kCGBlendModeDarken,

     kCGBlendModeLighten,

     kCGBlendModeColorDodge,

     kCGBlendModeColorBurn,

     kCGBlendModeSoftLight,

     kCGBlendModeHardLight,

     kCGBlendModeDifference,

     kCGBlendModeExclusion,

     kCGBlendModeHue,

     kCGBlendModeSaturation,

     kCGBlendModeColor,

     kCGBlendModeLuminosity,

     */

    [image2 drawAtPoint:CGPointMake(0, 0) blendMode:kCGBlendModeExclusion alpha:0.5];

}

相關文章
相關標籤/搜索