UI Development----Basic View and Program initiation Process (delegate)

Source: Internet
Author: User

Create by Guo Chai April 13, 2015 22:10:23

The basic views presented today include: Uitextfield, UIButton

I. Definition Uitextfield:

Creating a Uitextfield is similar to the procedure for creating a uilabel.

1. Open up space and initialize (if this class has an initialization method, so that the use of the "self", or the use of the parent class).
2, set the text display, the output of the relevant properties?
3, add to the parent view, to show?
4. Release

Uitextfield * TextField = [[Uitextfield alloc] Initwithframe:cgrectmake (+, +, +)];    Textfield.backgroundcolor = [Uicolor cyancolor];    [Self.window Addsubview:textfield];    [TextField release];
Common Properties and methods:

Text display:


Input control:


Appearance control:


Code implementation:

Textfield.text = @ "Hello Guo Chai";    Textfield.textcolor = [Uicolor redcolor];    Textfield.textalignment = Nstextalignmentcenter;    Textfield.font = [Uifont systemfontofsize:12];    Textfield.font = [Uifont fontwithname:@ "Helveticabold" size:12];    Textfield.placeholder = @ "Please enter user name";    textfield.enabled = NO;    textfield.clearsonbeginediting = YES;    Textfield.securetextentry = YES;    Textfield.keyboardtype = Uikeyboardtypenumberpad;    Textfield.returnkeytype = Uireturnkeynext;    Textfield.inputview = Self.window;

    UIView * view = [[UIView alloc] Initwithframe:cgrectmake ([+], []];    View.backgroundcolor = [Uicolor greencolor];            The Bank security input password is a transform keyboard, view is the keyboard that you added    //Textfield.inputview = view;    Textfield.inputaccessoryview = view;    [View release];

textField.borderStyle    = Uitextborderstyleroundedrect;            Textfield.clearbuttonmode = uitextfieldviewmodewhileediting;    UIView * Leftview = [[UIView alloc] Initwithframe:cgrectmake (0, 0, 10, 10)];            Leftview.backgroundcolor = [Uicolor Bluecolor];    Textfield.leftview = Leftview;        Textfield.leftviewmode = Uitextfieldviewmodealways;    UIView * Rightview = [[UIView alloc] Initwithframe:cgrectmake (0, 0, 10, 10)];          Rightview.backgroundcolor = [Uicolor Redcolor];    Textfield.rightview = Rightview;        Textfield.rightviewmode = Uitextfieldviewmodealways;    =================================================//set itself as proxy textfield.delegate = self;    Set TextField as the first responder, directly eject the keyboard, the cursor is directly located in the TextField [TextField Becomefirstresponder];    ================================================= [Leftview release]; [Rightview release]; 
==================================================================


Get the font name in the system:

    Print out the system font    nsarray *array = [Uifont familynames];    For (NSString *s in array) {        NSLog (@ "%@", s);    }
==================================================================
UIButton:

Use of UIButton:

Creating UIButton is similar to the steps for creating Uilabel, Uitextfield, and UIView. 1. Create a Button object (if this class has an initialization method, make it a self-made, otherwise use the parent class).?
2, set the button display related properties?
3. Add a Click event for the button? 4. Add a button to the parent view, to show the display? 5, button? Do not need to be released (because the use of the class? Method creates a button)

Create UIButton:

UIButton * btn = [UIButton buttonwithtype:uibuttontypecustom];    Btn.frame = CGRectMake (+,--);    Btn.backgroundcolor = [Uicolor greencolor];    [Btn settitle:@ "Landing" forstate:uicontrolstatenormal];    [Btn settitle:@ "Landing" forstate:uicontrolstatehighlighted];    Add button event    [btn addtarget:self action: @selector (Login:) forcontrolevents:uicontroleventtouchupinside];
    [Self.window ADDSUBVIEW:BTN];
UIButton from the parent class Uicontrol that inherits control-related methods, like adding things
Remove events, and so on.
Note: UIButton:UIControl:UIView

UIButton Add Event:



Appearance control:



Code implementation:

UIButton * btn = [UIButton buttonwithtype:uibuttontypecustom];    Btn.frame = CGRectMake (100, 150, 100, 60);    Btn.backgroundcolor = [Uicolor Greencolor];    [Btn settitle:@ "Landing" forstate:uicontrolstatenormal];    [Btn settitle:@ "Landing" forstate:uicontrolstatehighlighted];    Add button event [btn addtarget:self action: @selector (Login:) forcontrolevents:uicontroleventtouchupinside];    Remove button Event//[BTN removetarget:self Action: @selector (Login:) forcontrolevents:uicontroleventtouchupinside];    [btn Settitlecolor:[uicolor Redcolor] forstate:uicontrolstatenormal];    [btn Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatehighlighted];        [Btn settitle:@ "Cancel" forstate:uicontrolstatehighlighted];    UIImage * img = [UIImage imagenamed:@ "3.png"];    [Btn setimage:img Forstate:uicontrolstatenormal];    UIImage * Img2 =[uiimage imagenamed:@ "4.png"];        [Btn Setimage:img2 forstate:uicontrolstatehighlighted]; Set the picture to the background [btn setbackgroundimage:img Forstate:uicoNtrolstatenormal];     [Btn Setbackgroundimage:img2 forstate:uicontrolstatehighlighted];


===========================================================================

Delegate

Click Return to recycle the keyboard:

Click the Keyboard return button to achieve the keyboard recycling steps: 1, the AppDelete as Uitextfield Delegate 2, AppDelete.h? File accept Uitextfielddelegate Agreement 3, APPDELETE.M? File implementation Textfieldshouldreturn:? method.

Code implementation:

first of all to abide by uitextfielddelegate Protocol.

<span style= "color: #333333;" >    //set itself as Agent    textfield.delegate = self;    Set TextField as the first responder, directly eject the keyboard, the cursor is directly located in the TextField    [TextField becomefirstresponder];</span>

-(BOOL) Textfieldshouldreturn: (Uitextfield *) textfield{    //Cancel First responder    [TextField Resignfirstresponder];    NSLog (@ "You clicked the Return button");    return YES;}

========================================================================

iOS program startup process:

Uiapplicationmain:

Uiapplicationmain in the procedure, the main function of the function of the tune, mainly to achieve 3
Function: Create a should? Program (UIApplication) instance to create the application proxy instance
Build up the event cycle (Runloop: The dead cycle, constantly detect the operation of the program, whether it is touched, shaking, etc.)

int Uiapplicationmain (!
int argc,!
Char *argv[],!
NSString *principalclassname,!
NSString *delegateclassname!
);! 1, Principalclassname: Should be? The class name of the program object (uiapplication or its sub-class)! 2. Delegateclassname: The class name to be used by the program delegate. (Any class that accepts uiapplicationdelegate)! Uiapplicationmain based on the above two class names, create a program instance, a program proxy instance.
Then build the event Loop (Runloop), detect the various events of the program (the program starts, receives the touch and so on);

==============

Application proxy:

Uiapplicationdelegate is? An OC protocol. What's the statement? A bunch of methods, these?
The law is related to the status of the application, which is implemented by the program agent. The UIApplication object is responsible for the adjustment.
Some of the methods defined in Uiapplicationdelegate:


================================================================================

UIWindow:

UIWindow as a window for the application of the program, it should be loaded when the program is started.
Various UI interface faces are rendered by window. UIWindow should be the same as the screen when it is created. by [UIScreen
Mainscreen].bounds can get the screen, big or small.
[Self.window makekeyandvisible];//makes window visible, that is, display window.

================================================================================


UI Development----Basic View and Program initiation Process (delegate)

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.