Uilabel * label = [[Uilabel alloc] init]; label. Text = @" Xxx " ; Label. Frame = Cgrectmake ( 0 , 0 , 100 , 100 ); Label. backgroundcolor = [Uicolor redcolor]; // Add events. Label. userinteractionenabled = Yes;Uitapgesturerecognizer * Singletap = [[Uitapgesturerecognizer alloc] initwithtarget: Self action: @ selector (handlesingletap :)]; [label addgesturerecognizer: singletap]; [singletap release]; [self. view addsubview: Label]; [label release]; // Event Method -( Void ) Handlesingletap :( uigesturerecognizer * ) Gesturerecognizer { // Event processing. }
# Import " Labeltestviewcontroller. h " @ Implementation Labeltestviewcontroller /* Accessing the text attributes text property font property textcolor property textalignment property linebreakmode property enabled property sizing the label's text comment property has property defined property example numberoflines Property Managing highlight values comment property highlighted property drawing A shadow shadowcolor property shadowoffset property drawing and positioning overrides-textrectforbounds: limitedtonumberoflines: None-drawtextinrect: None setting and getting attributes userinteractionenabled Property */ // Implement viewdidload to do additional setup after loading the view, typically from a nib. -( Void ) Viewdidload {uilabel * Label1 = [[uilabel alloc] initwithframe: cgrectmake ( 50.0 , 20.0 , 200.0 , 50.0 )]; Uilabel * Label2 = [[uilabel alloc] initwithframe: cgrectmake ( 50.0 , 80.0 , 200.0 , 50.0 )]; Uilabel * Label3 = [[uilabel alloc] initwithframe: cgrectmake ( 50.0 , 140.0 , 200.0 , 50.0 )]; Uilabel * Label4 = [[uilabel alloc] initwithframe: cgrectmake ( 50.0 , 200.0 , 200.0 , 50.0 )]; Uilabel * Label5 = [[uilabel alloc] initwithframe: cgrectmake ( 50.0 ,260.0 , 200.0 , 50.0 )]; Uilabel * Label6 = [[uilabel alloc] initwithframe: cgrectmake ( 50.0 , 320.0 , 200.0 , 50.0 )]; Uilabel * Label7 = [[uilabel alloc] initwithframe: cgrectmake ( 50.0 , 380.0 , 200.0 ,50.0 )]; // Set display text Label1.text = @" Label1 " ; Label2.text = @" Label2 " ; Label3.text = @" Label3 -- label3 -- label3 -- label3 -- label3 -- label3 -- label3 -- label3 -- label3 -- label3 -- label3 -- label3 -- " ; Label4.text = @" Label4 -- label4 -- label4 -- label4 -- " ; Label5.text = @" Label5 -- label5 -- label5 -- label5 -- label5 -- label5 -- " ; Label6.text = @" Label6 " ; Label7.text =@" Label7 " ; // Set the font: bold. The correct fontofsize is systemfontofsize. Label1.font = [uifont boldsystemfontofsize: 20 ]; // Set text color Label1.textcolor = [Uicolor orangecolor]; label2.textcolor = [Uicolor purplecolor]; // Set Text Location Label1.textalignment = Uitextalignmentright; label2.textalignment = Uitextalignmentcenter; // Set Font size to fit label width Label4.adjustsfontsizetofitwidth = Yes; // Set the number of lines of the label Label5.numberoflines = 2 ; Uilabel. backgroudcolor = [Uicolor clearcolor]; // You can remove the background color. // Set highlight Label6.highlighted = Yes; label6.highlightedtextcolor = [Uicolor orangecolor]; // Set shadow Label7.shadowcolor = [Uicolor redcolor]; label7.shadowoffset = Cgsizemake ( 1.0 , 1.0 ); // Set whether to interact with users Label7.userinteractionenabled = Yes; // Set whether the text in the label is variable. The default value is yes. Label3.enabled = No; // Set the display format when the text is too long Label3.linebreakmode = uilinebreakmodemiddletruncation; // Intercept // Typedef Enum { // Uilinebreakmodewordwrap = 0, // Uilinebreakmodecharacterwrap, // Uilinebreakmodeclip, // Cut off extra parts // Uilinebreakmodeheadtruncation, // Cut the header // Uilinebreakmodetailtruncation, // Cut off the tail // Uilinebreakmodemiddletruncation, // Intercept // } Uilinebreakmode; // If the adjustsfontsizetofitwidth attribute is set to yes, this attribute controls the behavior of the text baseline. Label4.baselineadjustment = Uibaselineadjustmentnone; // Typedef Enum { // Uibaselineadjustmentalignbaselines, // Uibaselineadjustmentaligncenters, // Uibaselineadjustmentnone, // } Uibaselineadjustment; [Self. view addsubview: label1]; [self. view addsubview: label2]; [self. view addsubview: label3]; [self. view addsubview: label4]; [self. view addsubview: label5]; [self. view addsubview: label6]; [self. view addsubview: label7]; [label1 release]; [label2 release]; [label3 release]; [label4 release]; [label5 release]; [label6 release]; [label7 release]; [Super viewdidload];} /* // Override to allow orientations other than the default portrait orientation.-(bool) specify :( uiinterfaceorientation) interfaceorientation {// return YES For supported orientations return (interfaceorientation = optional );} */ -( Void ) Didreceivememorywarning { // Releases the view if it doesn' t have a superview. [Super didreceivememorywarning]; // Release any cached data, images, etc that aren't in use. } -( Void ) Viewdidunload { // Release any retained subviews of the main view. // E.g. Self. myoutlet = nil; } -( Void ) Dealloc {[Super dealloc];} @ End
Uilabel * Label = [[uilabel alloc] initwithframe: cgrectmake ( 10 ,10 , 300 , 100 )]; Label. Text = @" I'm sorry, I'm sorry, I'm sorry ~~~ " ; [Self. View addsubview: Label]; cgrect Frame = Label7.frame; frame. Origin. x =- 180 ; Label. Frame = Frame; [uiview beginanimations: @" Testanimation " Context: NULL]; [uiview setanimationduration: 8.8f ]; [Uiview setanimationcurve: uiviewanimationcurvelinear]; [uiview setanimationdelegate: Self]; [uiview setanimationrepeatautoreverses: No]; [uiview setanimationrepeatcount: 999999 ]; Frame = Label. frame; frame. Origin. x = 350 ; Label. Frame = Frame; [uiview commitanimations];