Graphics Reference
In-Depth Information
//create attributed string
NSMutableAttributedString *string = nil ;
string = [[ NSMutableAttributedString alloc ] initWithString :text];
//convert UIFont to a CTFont
CFStringRef fontName = ( __bridge CFStringRef )font. fontName ;
CGFloat fontSize = font. pointSize ;
CTFontRef fontRef = CTFontCreateWithName (fontName, fontSize, NULL );
//set text attributes
NSDictionary *attribs = @{
( __bridge id ) kCTForegroundColorAttributeName :
( __bridge id )[ UIColor blackColor ]. CGColor ,
( __bridge id ) kCTFontAttributeName : ( __bridge id )fontRef
} ;
[string setAttributes :attribs range : NSMakeRange ( 0 , [text length ])];
attribs = @{
( __bridge id ) kCTForegroundColorAttributeName :
( __bridge id )[ UIColor redColor ]. CGColor ,
( __bridge id ) kCTUnderlineStyleAttributeName :
@( kCTUnderlineStyleSingle ) ,
( __bridge id ) kCTFontAttributeName : ( __bridge id )fontRef
} ;
[string setAttributes :attribs range : NSMakeRange ( 6 , 5 )];
//release the CTFont we created earlier
CFRelease (fontRef);
//set layer text
textLayer. string = string;
}
@end
Search WWH ::




Custom Search