[IPhone application development] iPhone application development 3: uilable and uitextfield

Source: Internet
Author: User

I. uilabel

(1) initialize uilabel

Uilabel * scorelabel = [[uilabel alloc] initwithframe: cgrectmake (self. bounds. Size. width/2),0.0,150.0,43.0)];

Scorelabel. textalignment = uitextalignmentcenter;

Scorelabel. Text =@"I'm Andy -- Qingfeng";

Scorelabel. textcolor = [uicolor whitecolor];

Scorelabel. backgroundcolor = [uicolor blackcolor];

Scorelabel. font = [uifont fontwithname:@"Arial rounded Mt bold"Size :(36.0)];

[Self addsubview: scorelabel];

 

(2) detailed parameter explanation:

//  Set display text  

Scorelabel. Text = @" I'm Andy -- Qingfeng " ;



// Set the font: bold. The system fontofsize is normal and the system font configuration is called.

Scorelabel. font = [uifont boldsystemfontofsize: 20 ];



// Set the text color. You can select multiple colors.

Scorelabel. textcolor = [uicolor orangecolor];

Scorelabel. textcolor = [uicolor purplecolor];



// Set the text alignment position, Center, Center, and right

Scorelabel. textalignment = uitextalignmentright;

Scorelabel. textalignment = uitextalignmentcenter;

// Set the font size to fit the label width.

Scorelabel. adjustsfontsizetofitwidth = yes;



// Set the number of lines of the label. This can be set according to the uitextview in the previous section.

Scorelabel. numberoflines = 2 ;



// Set whether the text is highlighted or not.

Scorelabel. Highlighted = yes;

Scorelabel. highlightedtextcolor = [uicolor orangecolor];



// Set the offset between the shadow color and the shadow.

Scorelabel. shadowcolor = [uicolor redcolor];

Scorelabel. shadowoffset = cgsizemake ( 1.0 , 1.0 );



// Set whether to interact with users

Scorelabel. userinteractionenabled = yes;



// Set whether the text in the label is variable. The default value is yes.

Scorelabel. Enabled = no;



// Set the display format when the text is too long

Scorelabel. linebreakmode = uilinebreakmodemiddletruncation; // Intercept


The following formats can be displayed in the definition:

  //  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.

 
Scorelabel. baselineadjustment = uibaselineadjustmentnone;


The following formats can be displayed in the definition:

// Typedef Enum {// uibaselineadjustmentalignbaselines, // uibaselineadjustmentaligncenters, // uibaselineadjustmentnone, //} uibaselineadjustment;

 

// Set the background color to transparent

 
Scorelabel. backgroudcolor = [uicolor clearcolor];


You can also use custom colors:

 
Uicolor * color = [uicolor colorwithred: 1.0f Green: 50366f Blue: 0.0f ALPHA: 1.0f]; scorelabel. textcolor = [uicolor color]; // The RGB value in uicolor is of the cgfloat type ranging from 0 ~ The value ranges from 0 to 1 ~ The color value range of 255.


 

Ii. uitextfield

(1) initialize uitextfield

 
Uitextfield * text = [[uitextfield alloc] initwithframe: cgrectmake (10, 50,300, 30)]; text. borderstyle = uitextborderstyleroundedrect; text. autocorrectiontype = uitextautocorrectiontypeyes; text. placeholder = @ "Hello, I'm Andy-Qingfeng"; text. returnkeytype = uireturnkeydone; text. clearbuttonmode = uitextfieldviewmodewhileediting; [text setbackgroundcolor: [uicolor whitecolor]; text. delegate = self; [self. view addsubview: text];

(2) detailed parameter explanation

Borderstyle: border style of the text box

Autocorrectiontype: You can set whether to enable the automatic reminder correction function.

Placeholder: Set the default text display.

Returnkeytype: Specifies the keyboard completion button.

Backgroundcolor: Set the background color.

Delegate: Set Delegation

(3) delegate Method

 

-(Void) Textfielddidbeginediting :( uitextfield *) textfield;

//The method that will be called when you click textfield.



-(Void) Textfielddidendediting :( uitextfield *) textfield;

//Method called when textfield editing ends

//Press the call method of the done button to make the keyboard disappear.

-(Bool) textfieldshouldreturn :( uitextfield *) textfield {

[Textfield resignfirstresponder];

ReturnYes;

}

Today we will introduce uilabel and uitextfield. Next we will talk about uiimageview and uiwebview. Thank you for your support.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.