自学1

作者: su_19 | 来源:发表于2016-04-12 17:50 被阅读42次
- (void)drawRect:(CGRect)rect{

    [super drawRect:rect];
    
    
    
    
    //获取当前上下文
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    //坐标点转换(低层的左下角是(0,0),UIKit是左上角为(0,0))
    CGContextSetTextMatrix(context, CGAffineTransformIdentity)
    ;
    CGContextTranslateCTM(context, 0, self.bounds.size.height);
    CGContextScaleCTM(context, 1.0, -1.0);
    
    

    
    //创建绘制区域
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathAddEllipseInRect(path, NULL, self.bounds);
    
    //文字
    NSMutableAttributedString * attristr = [[NSMutableAttributedString alloc] initWithString:@"This is a test 文字字符"];
    
    
    //设置字体大小属性
    //    CTFontRef font = CTFontCreateWithName(CFSTR("Georgia"), 30, NULL);
    //    [attristr addAttribute:(id)kCTFontAttributeName value:(__bridge id)font range:NSMakeRange(0, 4)];
    
    
    //设置斜体字
    //    CTFontRef font2 = CTFontCreateWithName((CFStringRef)[UIFont italicSystemFontOfSize:25].fontName, 30, NULL);
    //
    //    [attristr addAttribute:(id)kCTFontAttributeName value:(__bridge id)font2 range:NSMakeRange(0, 4)];
    
    
    //下划线
    //    [attristr addAttribute:(id)kCTUnderlineStyleAttributeName value:[NSNumber numberWithInt:kCTUnderlineStyleSingle] range:NSMakeRange(0, 4)];
    //    [attristr addAttributes:@{(id)kCTUnderlineStyleAttributeName:[NSNumber numberWithInt:kCTUnderlineStyleSingle],NSUnderlineColorAttributeName:[UIColor blueColor]} range:NSMakeRange(0, 4)];
    
    //下划线颜色
    //    [attristr addAttributes:@{(id)kCTUnderlineColorAttributeName:[UIColor redColor]} range:NSMakeRange(0, 4)];
    
    
    //设置字体间隔
    //    long number = 9;
    //    CFNumberRef num = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt8Type, &number);
    //    [attristr addAttribute:(id)kCTKernAttributeName value:(__bridge id)num range:NSMakeRange(10, 4)];
    
    //设置字体颜色
    //    [attristr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 4)];
    
    //设置空心字
    long number = 3;
    CFNumberRef num = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt8Type, &number);
    [attristr addAttribute:(id)kCTStrokeWidthAttributeName value:(__bridge id)num range:NSMakeRange(0, 4)];
    
    //设置空心颜色
    [attristr addAttribute:NSStrokeColorAttributeName value:(id)[UIColor blueColor] range:NSMakeRange(0, 4)];
    
    CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attristr);
    
    
    CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, [attristr length]), path, NULL);
    
    CTFrameDraw(frame, context);
    
    
    CFRelease(frame);
    CFRelease(path);
    CFRelease(framesetter);
    
    
    
}

相关文章

  • 自学1

  • android 自学必备网站

    一,Android 自学网站 给 Android 自学者朋友推荐几个自学网站: 1. Android Develo...

  • 第18节:三步联网学口语(六)

    一、单词自学笔记 以Lesson 2&3为例,演示如何自学单词。要求孩子自学1-24课的单词。 二、百词结网 1、...

  • 自学能力

    读《自学是门手艺》-1 99%的人终生都没有掌握自学能力。 这是多么可怕的事情。 而那掌握自学能力的1%的人,显然...

  • PS自学(1)

    自学PS,形成下面的绘画风格。

  • 自学make(1)

    make自动确定需要重新编译大型程序的哪些部分,并发出命令以重新编译它们。 1 要使用make 必须编写一个名为m...

  • 自学水彩1

    颜色未干接着涂色,出现了混色

  • 自学建议·1

    序 如果有道无形的墙将你和学习隔开,如果你想作长跑的学习者,如果你想享受学习,我有三点建议。(不适用于赶DDL的)...

  • 自学之路(1)

    快过年了,孩子们都回来了,我也开始变得忙碌起来。所以白天没有时间,只有在晚上可以画画。 昨晚画了一个小女孩,因为晚...

  • 自学绘画-1

    有点丑,但是还是会继续努力的!

网友评论

      本文标题:自学1

      本文链接:https://www.haomeiwen.com/subject/yqmilttx.html