# Import <coretext/coretext. h>
# Import <quartzcore/quartzcore. h>
Nsattributedstring * getattributedstring (){
Nsmutableattributedstring * attristring = [[nsmutableattributedstring
Alloc] initwithstring: @ "this is test! "]
Autorelease];
// Change the font color of this to red
[Attristring addattribute nsstring *) kctforegroundcolorattributename
Value ID) [uicolor
Redcolor]. cgcolor
Range: nsmakerange (0,
4)];
// Turns is yellow
[Attristring addattribute nsstring *) kctforegroundcolorattributename
Value ID) [uicolor
Yellowcolor]. cgcolor
Range: nsmakerange (5,
2)];
// Change the font of this. The value must be a ctfontref.
[Attristring addattribute nsstring *) kctfontattributename
Value ID) ctfontcreatewithname (cfstringref) [uifont
Boldsystemfontofsize: 14]. fontname,
14,
Null)
Range: nsmakerange (0,
4)];
// Underline this. value can be selected in the specified enumeration.
[Attristring addattribute nsstring *) kctunderlinestyleattributename
Value ID) [nsnumber
Numberwithint: kctunderlinestyledouble]
Range: nsmakerange (0,
4)];
Return attristring;
}
@ Interface tview: uiview
@ End
@ Implementation tview
-(ID) initwithframe :( cgrect) Frame
{
Self = [Super
Initwithframe: frame];
If (Self ){
Self. backgroundcolor = [uicolor
Clearcolor];
}
Return self;
}
-(Void) drawrect :( cgrect) rect {
[Super drawrect: rect];
Nsattributedstring * attristring =
Getattributedstring ();
Cgcontextref CTX =
Uigraphicsgetcurrentcontext ();
Cgcontextconcatctm (CTX,
Cgaffinetransformscale (cgaffinetransformmaketranslation (0, rect. Size. Height ),
1. f,-1.f ));
// Cgcontexttranslatectm (CTX, 0, rect. Size. Height );
// Cgcontextscalectm (CTX, 1,-1 );
Ctframesetterref framesetter =
Ctframesettercreatewithattributedstring (cfattributedstringref) attristring );
Cgmutablepathref Path =
Cgpathcreatemutable ();
Cgpathaddrect (path, null, rect );
Ctframeref frame =
Ctframesettercreateframe (framesetter, cfrangemake (0,
0), path, null );
Cfrelease (PATH );
Cfrelease (framesetter );
Ctframedraw (frame, CTX );
Cfrelease (FRAME );
}
@ End
@ Interface bidviewcontroller ()
@ End
@ Implementation bidviewcontroller
-(Void) viewdidload
{
[Super
Viewdidload];
Tview * view = [[tview
Alloc] initwithframe: cgrectmake (0,
(0,200,200)];
[Self. View
Addsubview: View];
[View release];
Catextlayer * textlayer = [catextlayer
Layer];
Textlayer. String = getattributedstring ();
Textlayer. Frame = cgrectmake (0,
Cgrectgetmaxy (view. Frame ),
200,200 );
[Self. View. Layer
Addsublayer: textlayer];
}
-(Void) viewdidunload
{
[Super
Viewdidunload];
// Release any retained subviews of the main view.
}
-(Bool) shouldautorotatetointerfaceorientation :( uiinterfaceorientation) interfaceorientation
{
Return (interfaceorientation! =
Uiinterfaceorientationportraitupsidedown );
}
@ End
Converted from created by zhangao on 5/30/12.