8-2简单绘图~

8-2 我不愿意成为你退而求其次的人

绘制一个相交直线,交界处设置为圆角;绘制一个圆角矩形边框;绘制一个填充矩形;绘制一个椭圆边框;绘制一个填充椭圆。

 const CGPoint points1[] =
    {CGPointMake(10 , 40), CGPointMake(100 , 40), CGPointMake(100 , 40) , CGPointMake(20, 70)};
    // 使用points1绘制一个相交直线,交界处设置为圆角;
    CGContextRef ref = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(ref, 10);
    CGContextSetStrokeColorWithColor(ref, [UIColor purpleColor].CGColor);
    CGContextSetLineCap(ref, kCGLineCapRound);
    CGContextStrokeLineSegments(ref, points1, 4);
    
    // 绘制一个圆角矩形边框;
    CGContextRef ref2 = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(ref2, 10);
    CGContextSetStrokeColorWithColor(ref2, [UIColor purpleColor].CGColor);
    CGContextSetLineJoin(ref2, kCGLineJoinRound);
    CGContextStrokeRect(ref2, CGRectMake(30, 130, 100, 100));
    
    // 绘制一个填充矩形;
    CGContextRef ref3 = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(ref2, 10);
    CGContextSetFillColorWithColor(ref3, [UIColor purpleColor].CGColor);
    CGContextFillRect(ref3, CGRectMake(30, 250, 100, 50));
    
    // 绘制一个椭圆边框;
    CGContextRef ref4 = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(ref4, 10);
    CGContextSetStrokeColorWithColor(ref4, [UIColor purpleColor].CGColor);
    CGContextStrokeEllipseInRect(ref4, CGRectMake(30, 350, 100, 30));
    
    // 绘制一个填充椭圆。(填充和边框颜色都使用方法...ColorWithColor()设置为紫色)
    CGContextRef ref5 = UIGraphicsGetCurrentContext();
    CGContextSetLineWidth(ref5, 10);
    CGContextSetFillColorWithColor(ref5, [UIColor purpleColor].CGColor);
    CGContextFillEllipseInRect(ref5, CGRectMake(30, 450, 100, 30));

点线模式,绘制虚线的直线 矩形 圆

    // 获取当前绘图上下文
    CGContextRef ref = UIGraphicsGetCurrentContext();
    // 设置rgb颜色
    CGContextSetRGBStrokeColor(ref, 1.0, 0, 1.0, 1);
    // 绘制线条宽度
    CGContextSetLineWidth(ref, 2);
    // 设置数组,先绘制30个点,跳过30个点,以此类推
    CGFloat dashLengths[] = {30, 30};
    // 设置为点线模式,2为dashLengths的个数
    CGContextSetLineDash(ref, 0.0, dashLengths, 2);
    CGPoint line1[] = {CGPointMake(10, 20),CGPointMake(360, 20)};
    CGContextStrokeLineSegments(ref, line1, 2);
    
    CGContextStrokeRect(ref, CGRectMake(50, 50, 100, 100));

    CGContextStrokeEllipseInRect(ref, CGRectMake(50, 200, 100, 50));

绘制文本

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetCharacterSpacing (context, 4);
    CGContextSetRGBFillColor (context, 1, 0, 1, 1);
    CGContextSetRGBStrokeColor (context, 0, 0, 1, 1);
    CGContextSetTextDrawingMode (context, kCGTextFill);
    
    NSDictionary *attribute = @{NSFontAttributeName:[UIFont fontWithName:@"Heiti SC" size: 35],
                                NSForegroundColorAttributeName:[UIColor blueColor]};
    
    NSString *str1 = @"猿圈";
    NSString *str2 = @"猿圈-程序员的刷题神器";
    
    [str1 drawAtPoint:CGPointMake(10, 20) withAttributes:attribute];
    
    // 设置模式为描边模式kCGTextStroke
    CGContextSetTextDrawingMode(context, kCGTextStroke);
    [str2 drawAtPoint:CGPointMake(10, 50) withAttributes:attribute];
    
    // 设置描边填充模式绘制文本
    CGContextSetTextDrawingMode(context, kCGTextFillStroke);
    [str2 drawAtPoint:CGPointMake(10, 100) withAttributes:attribute];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.绘图板 制作绘图板中遇到的思路卡壳的点 画多个形状的图如何定义类 有的形状需要多个点 绘制不同颜色的图形时遇到...
    cry_0416阅读 215评论 0 0
  • UIBezierPath Class Reference 译:UIBezierPath类封装了Core Graph...
    鋼鉄侠阅读 1,781评论 0 3
  • (注:文中的 “移动” 均表示:鼠标拖拽移动) 第一天 调出路径查找器:Ctrl + Shift + F9; 联集...
    萌萌_1014阅读 1,540评论 0 0
  • 昨天晚上开始看 从0到1 这本书,真心觉得彼得·蒂尔是个很厉害的人。 书中写道:如果你不能把对手打败,那就和对手联...
    景深博文阅读 438评论 0 1
  • :如果26个英文字母 A B C D EF G H I J K L M N O P Q R S T U V W X...
    未央熠阅读 502评论 0 0