- (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...