Advertisement
Guest User

Untitled

a guest
May 24th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #import <CoreText/CoreText.h>
  2.  
  3. - (void)drawRect:(CGRect)rect {
  4. CGContextRef context = UIGraphicsGetCurrentContext();
  5. CGContextSetTextMatrix(context, CGAffineTransformMakeScale(1.0, -1.0));
  6. CGContextSetTextDrawingMode(context, kCGTextFill);
  7.  
  8. // CGContextShowTextAtPoint 를 사용하는 경우
  9. CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
  10. CGContextSelectFont(context, "Helvetica", 10.0, kCGEncodingMacRoman);
  11. NSString *textString = [[NSString alloc] initWithString:@"CGContextShowTextAtPoint"];
  12. CGContextShowTextAtPoint(context, 0, 10, [textString UTF8String], strlen([textString UTF8String]));
  13.  
  14. // CoreText 를 사용하는 경우
  15. NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"CoreText"];
  16.  
  17. CTFontRef helvetica = CTFontCreateWithName(CFSTR("Helvetica"), 10.0, NULL);
  18. [string addAttribute:(id)kCTFontAttributeName value:(__bridge id)helvetica range:NSMakeRange(0, [string length])];
  19. [string addAttribute:(id)kCTForegroundColorAttributeName value:(id)[UIColor blackColor].CGColor range:NSMakeRange(0, [string length])];
  20.  
  21. CTFramesetterRef textFramesetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef)string);
  22.  
  23. CGMutablePathRef textPath = CGPathCreateMutable();
  24. CGPathAddRect(textPath, NULL, CGRectMake(0, 10, 100, 20));
  25.  
  26. CTFrameRef textFrame = CTFramesetterCreateFrame(textFramesetter, CFRangeMake(0, 0), textPath, NULL);
  27.  
  28. CTFrameDraw(textFrame, context);
  29.  
  30. CFRelease(textFrame);
  31. CGPathRelease(textPath);
  32. CFRelease(textFramesetter);
  33. CFRelease(helvetica);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement