- (void)drawRect:(CGRect)rect
{
NSString *longText = @"CoreText"; /* ... */
NSRange rang =[self.hightString rangeOfString:longText];
longText = @"CoreText";
NSMutableAttributedString *string = [[NSMutableAttributedString alloc]
initWithString:longText]; if (rang.location == NSNotFound)
{ } // make a few words bold
CTFontRef helvetica = CTFontCreateWithName(CFSTR("Helvetica"), 14.0, NULL);
CTFontRef helveticaBold = CTFontCreateWithName(CFSTR("Helvetica-Bold"), 14.0, NULL); [string addAttribute:(id)kCTFontAttributeName
value:(__bridge id)helvetica
range:NSMakeRange(, [string length])]; [string addAttribute:(id)kCTForegroundColorAttributeName
value:(id)[UIColor redColor].CGColor
range:NSMakeRange(, )]; // layout master
CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString(
(CFAttributedStringRef)string); // left column form
CGMutablePathRef leftColumnPath = CGPathCreateMutable();
CGPathAddRect(leftColumnPath, NULL,
CGRectMake(, ,
self.bounds.size.width/2.0,
self.bounds.size.height)); // left column frame
CTFrameRef leftFrame = CTFramesetterCreateFrame(framesetter,
CFRangeMake(, ),
leftColumnPath, NULL); // right column form
CGMutablePathRef rightColumnPath = CGPathCreateMutable();
CGPathAddRect(rightColumnPath, NULL,
CGRectMake(self.bounds.size.width/2.0, ,
self.bounds.size.width/2.0,
self.bounds.size.height)); NSInteger rightColumStart = CTFrameGetVisibleStringRange(leftFrame).length; // right column frame
CTFrameRef rightFrame = CTFramesetterCreateFrame(framesetter,
CFRangeMake(rightColumStart, ),
rightColumnPath,
NULL); // flip the coordinate system
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
CGContextTranslateCTM(context, , self.bounds.size.height);
CGContextScaleCTM(context, 1.0, -1.0); // draw
CTFrameDraw(leftFrame, context);
CTFrameDraw(rightFrame, context); // cleanup
CFRelease(leftFrame);
CGPathRelease(leftColumnPath);
CFRelease(rightFrame);
CGPathRelease(rightColumnPath);
CFRelease(framesetter);
CFRelease(helvetica);
CFRelease(helveticaBold);
// [string release]; }

CoreText

05-11 14:50