Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <CoreText/CoreText.h>
- - (void)drawRect:(CGRect)rect {
- CGContextRef context = UIGraphicsGetCurrentContext();
- CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0, -1.0));
- CGContextSetTextDrawingMode(context, kCGTextFill);
- // CGContextShowTextAtPoint 를 사용하는 경우
- CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
- CGContextSelectFont(context, "Helvetica", 10.0, kCGEncodingMacRoman);
- NSString *textString = [[NSString alloc] initWithString:@"CGContextShowTextAtPoint"];
- CGContextShowTextAtPoint(context, 0, 10, [textString UTF8String], strlen([textString UTF8String]));
- // CoreText 를 사용하는 경우
- NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"CoreText"];
- CTFontRef helvetica = CTFontCreateWithName(CFSTR("Helvetica"), 10.0, NULL);
- [string addAttribute:(id)kCTFontAttributeName value:(__bridge id)helvetica range:NSMakeRange(0, [string length])];
- [string addAttribute:(id)kCTForegroundColorAttributeName value:(id)[UIColor blackColor].CGColor range:NSMakeRange(0, [string length])];
- CTFramesetterRef textFramesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)string);
- CGMutablePathRef textPath = CGPathCreateMutable();
- CGPathAddRect(textPath, NULL, CGRectMake(0, 10, 100, 20));
- CTFrameRef textFrame = CTFramesetterCreateFrame(textFramesetter, CFRangeMake(0, 0), textPath, NULL);
- CTFrameDraw(textFrame, context);
- CFRelease(textFrame);
- CGPathRelease(textPath);
- CFRelease(textFramesetter);
- CFRelease(helvetica);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement