IOS开发基础之绘图的样式
生活随笔
收集整理的這篇文章主要介紹了
IOS开发基础之绘图的样式
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
IOS開發(fā)基礎(chǔ)之繪圖的樣式
// LJView.m // 33-繪圖的樣式 // Created by 魯軍 on 2021/2/23. #import "LJView.h" @implementation LJView - (void)drawRect:(CGRect)rect { // [self testCStyle]; // [self testOCStyleOCcode];[self testSanjiaoxingOC]; } -(void)testSanjiaoxingOC{UIBezierPath *path = [UIBezierPath bezierPath];[path moveToPoint:CGPointMake(50, 50)];[path addLineToPoint:CGPointMake(100, 100)];[path addLineToPoint:CGPointMake(150, 50)];[path closePath];[path setLineWidth:30];[[UIColor redColor]setFill];[[UIColor blueColor] setStroke];//同時(shí)設(shè)置描邊的和填充的顏色[[UIColor greenColor] set];[path stroke];[path fill];} -(void)testSanjiaoxingC{CGContextRef ctx =UIGraphicsGetCurrentContext();CGContextMoveToPoint(ctx, 50, 50);CGContextAddLineToPoint(ctx, 100, 100);CGContextAddLineToPoint(ctx, 150, 50); // CGContextAddLineToPoint(ctx, 50, 50);CGContextClosePath(ctx); //關(guān)閉路徑CGContextSetLineWidth(ctx, 10); // CGContextStrokePath(ctx); //描邊//填充 // CGContextFillPath(ctx);//CGContextDrawPath(ctx, kCGPathStroke);[[UIColor redColor] setFill];[[UIColor blueColor] setStroke];CGContextDrawPath(ctx, kCGPathFillStroke); }-(void)testOCStyleOCcode{UIBezierPath *path =[UIBezierPath bezierPath];[path moveToPoint:CGPointMake(50, 50)];[path addLineToPoint:CGPointMake(100, 100)];[path addLineToPoint:CGPointMake(150, 50)];//設(shè)置線寬[path setLineWidth:30];//設(shè)置連接處樣式[path setLineJoinStyle:kCGLineJoinRound];//設(shè)置頭尾樣式[path setLineCapStyle:kCGLineCapRound];//OC 設(shè)置藍(lán)色[[UIColor blueColor] setStroke];[path stroke]; }-(void)testCStyle{CGContextRef ctx = UIGraphicsGetCurrentContext();CGContextMoveToPoint(ctx, 50, 50);CGContextAddLineToPoint(ctx, 100, 100);CGContextAddLineToPoint(ctx, 150, 50);//設(shè)置線寬CGContextSetLineWidth(ctx, 30);//連接處的樣式//kCGLineJoinMiter 默認(rèn)//kCGLineJoinBevel 切角//kCGLineJoinRound。圓角CGContextSetLineJoin(ctx, kCGLineJoinRound);//頭尾樣式//kCGLineCapButt。默認(rèn)//kCGLineCapRound。圓角//kCGLineCapSquare。方的。變短一點(diǎn)。CGContextSetLineCap(ctx, kCGLineCapSquare);//C 設(shè)置紅色CGContextSetRGBStrokeColor(ctx,1, 0, 0, 1);CGContextStrokePath(ctx); } @end總結(jié)
以上是生活随笔為你收集整理的IOS开发基础之绘图的样式的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 改良程序的11技巧
- 下一篇: IOS开发基础之绘制饼图、柱状图、自定义