IOS sign-in or sign-in page (Uilable,uitextfield,uibutton)

Source: Internet
Author: User
Tags set background

Sign up or sign in page

Such as

1, here in order to show the Uitextfield text box associated keyboard settings, here the "password" and "OK password" of the associated keyboard are set to the numeric keypad, the actual application of passwords are generally allowed to be numbers or letters.
2, realize the keyboard retract operation.
3, there is no code written to filter the "User name" for special characters.


Implementation code:

#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller-(void) viewdidload{[super    Viewdidload];        Additional setup after loading the view, typically from a nib.    Three x UILabel UILabel *namelabel = [[UILabel alloc]initwithframe:cgrectmake (10, 60, 80, 37)];    Namelabel.font = [Uifont systemfontofsize:15];    Namelabel.text = @ "user name:";    Namelabel.backgroundcolor = [Uicolor Clearcolor];    Namelabel.textalignment = Nstextalignmentleft;  Namelabel.numberoflines = 2;    Number of lines used to set Uilabel Chinese text [Self.view Addsubview:namelabel];        [Namelabel release];    UILabel *newpasswordlabel = [[UILabel alloc]initwithframe:cgrectmake (10, 60+40, 80, 37)];    Newpasswordlabel.font = [Uifont systemfontofsize:15];    Newpasswordlabel.text = @ "Password:";    Newpasswordlabel.backgroundcolor = [Uicolor Clearcolor];    Newpasswordlabel.textalignment = Nstextalignmentleft;    [Self.view Addsubview:newpasswordlabel];  [Newpasswordlabel release];      UILabel *oncepasswordlabel = [[UILabel alloc]initwithframe:cgrectmake (10, 60+40*2, 80, 37)];    Oncepasswordlabel.font = [Uifont systemfontofsize:15];    Oncepasswordlabel.text = @ "Confirm password:";    Oncepasswordlabel.backgroundcolor = [Uicolor Clearcolor];    Oncepasswordlabel.textalignment = Nstextalignmentleft;    [Self.view Addsubview:oncepasswordlabel];            [Oncepasswordlabel release];    Three input boxes Uitextfield *nametextfield = [[Uitextfield alloc]initwithframe:cgrectmake (90, 60, 210, 30)];    Nametextfield.placeholder = @ "Please enter user name";    Nametextfield.tag = 1;    [Nametextfield Setsecuretextentry:no];    Nametextfield.font = [Uifont systemfontofsize:14];    Nametextfield.delegate = self;    Nametextfield.backgroundcolor = [Uicolor Clearcolor];    Nametextfield.borderstyle = Uitextborderstyleroundedrect;    [Self.view Addsubview:nametextfield];        [Nametextfield release];   Uitextfield *passwordtextfield = [[Uitextfield alloc]initwithframe:cgrectmake (90, 60+40, 210, 30)]; Passwordtextfield.placeholder = @ "At least 6 digits";    Passwordtextfield.tag = 2;    [Passwordtextfield Setsecuretextentry:yes];    Passwordtextfield.font = [Uifont systemfontofsize:14];    Passwordtextfield.delegate = self;    Passwordtextfield.backgroundcolor = [Uicolor Clearcolor];    Passwordtextfield.borderstyle = Uitextborderstyleroundedrect;    Passwordtextfield.keyboardtype = Uikeyboardtypenumberpad;    [Self.view Addsubview:passwordtextfield];        [Passwordtextfield release];    Uitextfield *oncenewpasswordtextfield = [[Uitextfield alloc]initwithframe:cgrectmake (90, 60+40*2, 210, 30)];    Oncenewpasswordtextfield.placeholder = @ "Please enter your password again";    Oncenewpasswordtextfield.tag = 3;    Oncenewpasswordtextfield.font = [Uifont systemfontofsize:14];    [Oncenewpasswordtextfield Setsecuretextentry:yes];    Oncenewpasswordtextfield.delegate = self;    Oncenewpasswordtextfield.backgroundcolor = [Uicolor Clearcolor];    Oncenewpasswordtextfield.borderstyle = Uitextborderstyleroundedrect; OncenEwpasswordtextfield.keyboardtype = Uikeyboardtypenumberpad;    [Self.view Addsubview:oncenewpasswordtextfield];            [Oncenewpasswordtextfield release];    UIButton *confirmbutton = [UIButton buttonwithtype:uibuttontyperoundedrect];    Confirmbutton.frame = CGRectMake (110, 60+40*3+20, 100, 37);       [ConfirmButton settitle:@ "OK" forstate:uicontrolstatenormal];  The title of the button displayed under normal conditions [ConfirmButton settitle:@ "OK" forstate:uicontrolstatehighlighted];    The caption of the button when highlighted confirmbutton.backgroundcolor = [Uicolor Redcolor]; [ConfirmButton addtarget:self Action: @selector (confirm:) forcontrolevents:uicontroleventtouchupinside];// The event//@selector that occurs when the button is pressed and lifted can be understood as "selector", which is a pointer variable, similar to sender. Here is the method that is assigned to the new ConfirmButton [Self.view Addsubview:confirmbutton];} Retract keyboard-(void) Touchesbegan: (Nsset *) touches withevent: (uievent *) event{for (int i = 0; i<4; i++) {Uitextfie        LD *textfield = (uitextfield*) [Self.view viewwithtag:1+i]; [TextField ResignfirstResponder];    }}-(void) didreceivememorywarning{[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end

UILabel

Uilabel inherits the UIView, which can set the properties supported by UIView.

UILabel *label1 = [[UILabel alloc]initwithframe:cgrectmake (50.0, 20.0, 200.0, 50.0)]; Set the label's position and size//set display text Label1.Text = @ "username";//Set font: Bold, normal systemfontofsizelabel1.font = [Uifont boldsystemfontofsize:20];//Set Text color Label1.textcolor = [Uicolor orangecolor];//set text position label1.textalignment = Uitextalignmentright;label2.textalignment = uitextalignmentcenter;// Set the font size to fit the label width label4.adjustsfontsizetofitwidth = yes;//Set the number of lines of the label label5.numberoflines = 2; Uilabel.backgroudcolor=[uicolor Clearcolor]; Can remove 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 you can interact with the user label7.userinteractionenabled = yes;//Sets whether the text in the label is mutable, the default value is yeslabel3.enabled = no;//  Set the display format when the text is too long Label3.linebreakmode = uilinebreakmodemiddletruncation;//truncate the intermediate//typedef enum {//Uilinebreakmodewordwrap = 0,//uilinebreakmodecharacterwrap,//uilinebreakmodeclip,//cut off redundant parts//Uilinebreakmodeheadtruncation,//cut off the head//uilinebreakmodetailtruncation,//cut off the tail//uilinebreakmodemiddletruncation,//intercept the middle//} UILineBreakM  ode;//if the Adjustsfontsizetofitwidth property is set to Yes, this property controls the behavior of the text baseline label4.baselineadjustment = uibaselineadjustmentnone;// typedef enum {//uibaselineadjustmentalignbaselines,//uibaselineadjustmentaligncenters,//Uibaselineadjust mentnone,//} uibaselineadjustment;

Sometimes you need to set the number of Uilabel in Chinese, whose property value defaults to 1, to set the Uilabel to display only one line of text.

   Oldpasswordlabel.numberoflines = 2;

Uitextfield

Initialize the TextField and set the position and size uitextfield *text = [[Uitextfield alloc]initwithframe:cgrectmake (20, 20, 130, 30)];//When the input box has no content, Watermark hint, the content is "user name"//display gray font, as a hint message Text.placeholder = @ "username";//Set border style, only set to display border style Text.borderstyle =     uitextborderstyleroundedrect;typedef enum {uitextborderstylenone, uitextborderstyleline, UITextBorderStyleBezel,    Uitextborderstyleroundedrect} uitextborderstyle;//Set the keyboard style Text.keyboardtype = Uikeyboardtypenumberpad;typedef enum { Uikeyboardtypedefault,//default keyboard, support for all character uikeyboardtypeasciicapable,//ASCII-enabled default keyboard Uikeybo Ardtypenumbersandpunctuation,//Standard telephone keypad, support +*# character Uikeyboardtypeurl,//url keyboard, support. com buttons only support URL characters U Ikeyboardtypenumberpad,//numeric keypad uikeyboardtypephonepad,//Telephone keypad Uikeyboardtypenamephonepad              ,//telephone keypad, also supports entering person name uikeyboardtypeemailaddress,//keyboard uikeyboardtypedecimalpad for entering e-mail address,       The numeric keypad has numbers and decimal uikeyboardtypetwitter,          Optimized keyboard for easy input @, #字符 Uikeyboardtypealphabet = uikeyboardtypeasciicapable,} uikeyboardtype;//each character is entered into a dot cipher input te Xt.securetextentry = yes;//Sets the background color of the input box, which is set to white if a custom background picture border is used, it is ignored text.backgroundcolor = [Uicolor whitecolor];// Set background Image text.background = [UIImage imagenamed:@ "Dd.png"];//set background text.disabledbackground = [UIImage imagenamed:@ "Cc.png" ];//set font style and size for input box contents text.font = [Uifont fontwithname:@ "Arial" size:20.0f];//set font Color Text.textcolor = [Uicolor Redcolor]    If there is a fork in the input box, when it is displayed, it is used to delete the contents of the input box once Text.clearbuttonmode = Uitextfieldviewmodealways;typedef enum { Uitextfieldviewmodenever,//Never appears uitextfieldviewmodewhileediting,//editor appears Uitextfieldviewmodeunlessedi Ting,//In addition to the edit appear uitextfieldviewmodealways//always appear} uitextfieldviewmode;//input box in the beginning of the text Text.text = @ "Start in the input box     The text ";//whether error correction Text.autocorrectiontype = uitextautocorrectiontypeno;typedef enum {uitextautocorrectiontypedefault,//default Uitextautocorrectiontypeno,//Do not automatically correct UitextautocorreCtiontypeyes,//Auto Error correction} uitextautocorrectiontype;//empty text.clearsonbeginediting = yes;//content Alignment Text.textalignment = The vertical alignment of uitextalignmentleft;//content Uitextfield inherits from Uicontrol, There is an attribute in this class contentverticalalignmenttext.contentverticalalignment = uicontrolcontentverticalalignmentcenter;// When set to YES, the text automatically shrinks to fit the text window size. The default is to keep the original size while letting long text scroll textfied.adjustsfontsizetofitwidth = yes;// Sets the minimum font size for the auto-shrink display text.minimumfontsize = 20;//If the first letter is capitalized text.autocapitalizationtype = Uitextautocapitalizationtypenone; typedef enum {Uitextautocapitalizationtypenone, not automatically capitalized uitextautocapitalizationtypewords, Word first uppercase Uitextautocapit Alizationtypesentences, the first letter of the sentence is capitalized uitextautocapitalizationtypeallcharacters, all the letters are uppercase} Uitextautocapitalizationtype The//return key becomes Text.returnkeytype =uireturnkeydone;typedef enum {uireturnkeydefault,//Default Gray button, marked with return UI              Returnkeygo,//blue button labeled Go uireturnkeygoogle,//blue button labeled Google, Search Uireturnkeyjoin, The blue button labeled Join UireturnkeynexT,//blue button labeled next uireturnkeyroute,//blue button with route uireturnkeysearch,//Search-marked             Blue button uireturnkeysend,//blue button labeled Send Uireturnkeyyahoo,//blue button labeled Yahoo Uireturnkeyyahoo, blue button labeled Yahoo Uireturnkeyemergencycall,//Emergency call Button} uireturnkeytype;//keyboard appearance Textview.keyboardappearance=uik eyboardappearancedefault;typedef enum {uikeyboardappearancedefault,//default appearance, light gray uikeyboardappearancealert,//dark grey  Graphite Color} uireturnkeytype;//set proxy for implementing protocol Text.delegate = self;//add TextField to view [Self.window addsubview:text];//rightmost plus picture is the following code Left like Uiimageview *image=[[uiimageview alloc] initwithimage:[uiimage imagenamed:@ "Right.png"]];text.rightview=image; Text.rightviewmode = uitextfieldviewmodealways;typedef enum {uitextfieldviewmodenever, UITextFieldViewModeWhileEdit ING, uitextfieldviewmodeunlessediting, uitextfieldviewmodealways} uitextfieldviewmode;

When dealing with information such as passwords, you may want to hide the information you have entered.

Each character entered into a point, the term password input [Passwordtextfield setsecuretextentry:yes];

You can also set the keyboard associated with the text box, as follows:

Set the keyboard style Text.keyboardtype = uikeyboardtypenumberpad;typedef enum {    uikeyboardtypedefault,           //default keyboard, Supports all character    uikeyboardtypeasciicapable,           //ASCII-enabled default keyboard    uikeyboardtypenumbersandpunctuation,/  / Standard telephone keypad, support +*# character    Uikeyboardtypeurl,                      //url keyboard, support. com buttons only support URL character    uikeyboardtypenumberpad,  // Numeric keypad    Uikeyboardtypephonepad,            //Telephone keypad    Uikeyboardtypenamephonepad,          //telephone keypad, also support input person name    Uikeyboardtypeemailaddress,          //keyboard uikeyboardtypedecimalpad for entering e-mail address,//          numeric keypad with numbers and decimal    points Uikeyboardtypetwitter,          //optimized keypad for easy input @, #字符    Uikeyboardtypealphabet = uikeyboardtypeasciicapable,} Uikeyboardtype;    

Sometimes it is necessary to limit the length of the input text, and such operations are also very common and important.

Limit the length of the input text-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) Range Replacementstring: (NSString *) string{    if ([Textfield.text length] > MAXLENGTH)    {        Textfield.text = [ Textfield.text Substringtoindex:maxlength-1];        return NO;    }    return YES; }

UIButton

UIButton *button1 = [UIButton buttonwithtype:uibuttontyperoundedrect]; There are 6 kinds of button types that can be defined,//typedef enum {//Uibuttontypecustom = 0, custom style//Uibu Ttontyperoundedrect, Rounded rectangle//uibuttontypedetaildisclosure, Blue small arrow button, mainly to do detailed description with//Uibuttonty          Peinfolight, bright exclamation point//Uibuttontypeinfodark, dark exclamation point//Uibuttontypecontactadd,         Cross plus button//} Uibuttontype;         The position of the given button on the view Button1.frame = CGRectMake (20, 20, 280, 20);         Button background color button1.backgroundcolor = [Uicolor Clearcolor];         Set button fill picture//[button1 setimage:[uiimage imagenamed:@ "Btng.png"] forstate:uicontrolstatenormal];         Set button title [Button1 settitle:@ "click" Forstate:uicontrolstatenormal]; /* Forstate: The function of this parameter is to define the text of the button or the picture in which state will appear *///The following are several states//enum {//UIControlStateNormal = 0        , the general state appears//uicontrolstatehighlighted = 1 << 0, highlighted status show//uicontrolstatedisabled = 1 << 1, disabled status will only appear uicontrolstateselected = 1 << 2, check status//Uicontrolstateapplication = 0x00ff0000, when         Application flag when//uicontrolstatereserved = 0xff000000 is reserved for internal frame, can be regardless of his//};         /* * By default, when the button is highlighted, the color of the image is drawn darker, if this property is set to No, * then this function can be removed * *         button1.adjustsimagewhenhighlighted = NO;         /* As in the above case, by default, when the button is disabled, the image will be drawn darker, set NO to cancel the setting */button1.adjustsimagewhendisabled = NO;         /* This property is set to YES in the state, the button will glow */button1.showstouchwhenhighlighted = yes;                   /* Add an event to the button, there are a number of events, I will open a separate blog to introduce them, the following time means to press the button, and the finger off the screen when the event triggered, and the Web as the Click event. After triggering this event, execute Butclick: This method, addtarget:self, means that this method can also pass in the pointer of another class in this class */[Button1 addtarget:self Action: @selector (Butclick:) forcontrolevents:uIcontroleventtouchupinside]; display controls [Self.view Addsubview:button1];

A separate explanation:

UIButton *confirmbutton = [UIButton buttonwithtype:uibuttontyperoundedrect];    Confirmbutton.frame = CGRectMake (max, 60+40*3+20, Max, Notoginseng);    [ConfirmButton settitle:@ "OK" forstate:uicontrolstatenormal];       The title of the button displayed under normal conditions    [ConfirmButton settitle:@ "OK" forstate:uicontrolstatehighlighted];  The caption of the button when highlighted    Confirmbutton.backgroundcolor = [Uicolor redcolor];    [ConfirmButton addtarget:self Action: @selector (confirm:) forcontrolevents:uicontroleventtouchupinside];// The event//@selector that occurs when the button is pressed and lifted    can be understood as "selector", which is a pointer variable, similar to sender. Here is the method that is assigned to the new ConfirmButton    [Self.view Addsubview:confirmbutton];

To set the background picture for UIButton:

UIButton *confirmbutton = [UIButton buttonwithtype:uibuttontypecustom];    Confirmbutton.frame = CGRectMake (Ten, A, A, a);    UIImage *nextstepimage = [UIImage imagenamed:@ "App.png"];    UIImage *nextstepdownimage = [UIImage imagenamed:@ "App.png"];    Nextstepimage = [Nextstepimage resizableimagewithcapinsets:uiedgeinsetsmake (8, 8, 8, 8)];    Nextstepdownimage = [Nextstepdownimage resizableimagewithcapinsets:uiedgeinsetsmake (8, 8, 8, 8)];    [ConfirmButton setbackgroundimage:nextstepimage forstate:uicontrolstatenormal];    [ConfirmButton setbackgroundimage:nextstepdownimage forstate:uicontrolstatehighlighted];    [ConfirmButton settitle:@ "OK" forstate:uicontrolstatenormal];    [ConfirmButton addtarget:self Action: @selector (confirm:) forcontrolevents:uicontroleventtouchupinside];    [Self.view Addsubview:confirmbutton];

IOS sign-in or sign-in page (Uilable,uitextfield,uibutton)

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.