- (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
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 最近在研究MQ,考虑用RabbitMQ性价比会高一些。这次学习的途径是看RabbitMQ官方网站的英文文档(好歹C...