Quartz2D知识点聚合案例
生活随笔
收集整理的這篇文章主要介紹了
Quartz2D知识点聚合案例
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Quartz2D知識點聚合
基本
//畫圖片UIImage *image = [UIImage imageNamed:@"阿貍頭像"];[image drawInRect:rect];//字體NSString *title = @"標題";NSMutableDictionary *atr = [NSMutableDictionary dictionary];atr[NSFontAttributeName] = [UIFont systemFontOfSize:15];// atr[NSForeground?ColorAttributeName] = [UIColor greenColor];[title drawInRect:CGRectMake(120, 20, 100, 20) withAttributes:atr];//橢圓UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(10, 20, 70, 130)];[path stroke];//方形UIBezierPath *path1 = [UIBezierPath bezierPathWithRect:CGRectMake(10, 200, 10, 50)];[path1 stroke];//圓角方形UIBezierPath *path2 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(100, 30, 100, 100) cornerRadius:10];[path2 stroke];//一個角圓角UIBezierPath *path3 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(210, 90, 80, 70) byRoundingCorners:UIRectCornerTopRight cornerRadii:CGSizeMake(20, 30)];[path3 stroke];//圓弧UIBezierPath *path4 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(130, 230) radius:70 startAngle:0 endAngle:M_PI clockwise:YES];[path4 stroke]; // 1.獲得當前上下文CGContextRef ctx = UIGraphicsGetCurrentContext();// 2.拼接路徑UIBezierPath *path = [UIBezierPath bezierPath];[path moveToPoint:CGPointMake(10, 20)];[path addQuadCurveToPoint:CGPointMake(200, 80) controlPoint:CGPointMake(100, 200)];// 3. 添加路徑到上下文CGContextAddPath(ctx, path.CGPath);// 4.渲染上下文CGContextStrokePath(ctx);變換
//變換//平移 // CGContextTranslateCTM(ctx, 10, 20);//旋轉(zhuǎn)CGContextRotateCTM(ctx, M_PI_4);//縮放CGContextScaleCTM(ctx, 1.2, 1.2);上下文棧
- 先保存或者還原上下文棧,再設置狀態(tài)
生成圖片
UIImage *image = [UIImage imageNamed:@"小黃人"];UIGraphicsBeginImageContextWithOptions(image.size, YES, 0);[image drawAtPoint:CGPointZero];NSString *str = @"小黃人";[str drawAtPoint:CGPointZero withAttributes:nil];image = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();截圖
- 給定裁減區(qū)域再渲染
擦除
- 先渲染到上下文,再擦除
轉(zhuǎn)載于:https://www.cnblogs.com/ShaoYinling/p/4649718.html
總結(jié)
以上是生活随笔為你收集整理的Quartz2D知识点聚合案例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 5-python学习——条件语句
- 下一篇: Android学习之查看网络图片