// Extend
@ Interface appdelegate ()
{
Uiview * _ view;
}
// It is not the instance variable defined at the beginning of the definition of the class, but the instance variable defined at the later stage according to the requirements, which is uniformly defined in the extension in the. M file, which is invisible to the outside world.
@ End
@ Implementation appdelegate
-(Bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions
{
Self. Window = [[uiwindow alloc] initwithframe: [uiscreen mainscreen] bounds];
// Override point for customization after application launch.
Uiimage * IMA = [uiimage imagenamed: @ "a.jpg"];
Self. Window. backgroundcolor = [uicolor whitecolor];
[Self. Window makekeyandvisible];
_ View = [[uiview alloc] initwithframe: cgrectmake (0, 0,320,568)];
_ View. backgroundcolor = [uicolor graycolor];
[Self. Window addsubview: _ view];
[_ View release];
// Create uilabel
[Self createlabel];
// Create uitextfield
[Self createtextfield];
// Create a uialertview
[Self createalertview];
// Create uibutton
[Self createbutton];
Return yes;
}
-(Void) createbutton
{
Uibutton * button = [uibutton buttonwithtype: uibuttontyperoundedrect];
Button. Frame = cgrectmake (30,300,100, 40 );
Button. backgroundcolor = [uicolor whitecolor];
Button. layer. cornerradius = 5;
Nsinteger A = 1;
[Button settitle: [nsstring stringwithformat: @ "% lD", a] forstate: uicontrolstatenormal];
// Add a response event to the button
Button. tag= 100 +;
// The parameter after click is: who calls addtarget: Action: method. The parameter is, and the parameter can only be one.
[Button addtarget: Self action: @ selector (Click :) forcontrolevents: uicontroleventtouchupinside];
[_ View addsubview: button];
}
-(Void) Click :( uibutton *) button
{
// Button. textinputcontextidentifier = @ "AAA ";
Nslog (@ "% @", button );
}
-(Void) createtextfield
{
// Uitextfield is a subclass of uicontrol, and uicontrol is a subclass of uiview. Therefore, it is also a view, but it has two more functions than uiview: (1) text display (2) text editing
// Uitextfield is used in the same way as uiview.
// 1. Create an object
Uitextfield * field = [[uitextfield alloc] initwithframe: cgrectmake (50, 50,220, 30)];
// 2. Configure attributes
Field. backgroundcolor = [uicolor whitecolor];
// (1) set the border Style
/**
Uitextborderstylenone,
Uitextborderstyleline, border
Uitextborderstylebezel,
Uitextborderstyleroundedrect rounded corner
*/
Field. borderstyle = uitextborderstyleroundedrect;
// (2) set the text displayed silently (prompt text) in the input box, but not as part of the text content
Field. placeholder = @ "Enter the user name ";
// (3) set the text to start to display
Field. Text = @ "string ";
// (4) set the text color
Field. textcolor = [uicolor redcolor];
// (5) Alignment
Field. textalignment = nstextalignmentcenter;
// (6) text font
Field. font = [uifont fontwithname: @ "thonburi-bold" Size: 20];
// (7) Whether the input box is editable
Field. Enabled = yes;
// (8) Clear the input box at the beginning
Field. clearsonbeginediting = yes;
// (9) whether the text is displayed in the dot format (SET Password Mode)
Field. securetextentry = yes;
// (10) set the pop-up keyboard Style
// Field. keyboardtype = uikeyboardtypenumberpad;
// (11) display style in the lower right corner of the keyboard
Field. returnkeytype = uireturnkeygo;
// (11) proxy
// Proxy procedure:
// 1. Set proxy
Field. Delegate = self;
// 2. Obey the Protocol
// Uitextfielddelegate
// 3. Methods in the Implementation Protocol
// (Bool) textfieldshouldreturn :( uitextfield *) textfield
// (12) custom input View
Uiview * V1 = [[uiview alloc] initwithframe: cgrectmake (200, 0,568,100)];
V1.backgroundcolor = [uicolor redcolor];
// Field. inputview = V1;
// (13) Auxiliary view above the input View
Field. inputaccessoryview = V1;
// 3. Add to parent View
[_ View addsubview: Field];
// 4. Release ownership
[Field release];
}
// Triggered when the return button is clicked in the lower right corner of the keyboard.
-(Bool) textfieldshouldreturn :( uitextfield *) textfield
{
// Clear the keyboard to cancel the first responder
[Textfield resignfirstresponder];
Nslog (@ "click ");
Return yes;
}
-(Void) createalertview
{
}
// When you want to access the local variable defined in another method, the variable is defined as an instance variable. to access a variable in multiple methods, declare the variable as an instance variable.
-(Void) createlabel
{
/**
Uilabel is a control used to display text in iOS development. It is a subclass of uiview. right shift has all the functions of uiview, but it only has more text display functions than uiview.
The usage of uilabel is similar to that of uiview:
1. Create an object
2. Configure attributes
3. Add to parent View
4. Release ownership
Different controls only have different properties configured, that is, differences. To learn a new control, you only need to configure its unique properties.
*/
Uilabel * V1 = [[uilabel alloc] initwithframe: cgrectmake (100,100,100,100)];
V1.backgroundcolor = [uicolor whitecolor];
// Set the text displayed on the label
V1.text = @ "abcdefghijklmnopqrstuvwxyz ";
// Label text position
// 0 nstextalignmentleft left
// 1 nstextalignmentcenter Center
// 2 nstextalignmentright right
V1.textalignment = nstextalignmentcenter;
// Text line feed is 1 by default. If no limit is set for the number of lines, the value is set to 0.
V1.numberoflines = 0;
// The standard for line feed (Text truncation principle) is a group of words by default.
/**
Nslinebreakbywordwrapping = 0, wrap at word boundaries, default
Nslinebreakbycharwrapping, wrap at character boundaries
Nslinebreakbyclipping, simply clip
Nslinebreakbytruncatinghead, truncate at head of line: "... wxyz"
Nslinebreakbytruncatingtail, truncate at tail of line: "ABCD ..."
Nslinebreakbytruncatingmiddle truncate middle of line: "AB... YZ"
*/
V1.linebreakmode = nslinebreakbyclipping;
// Set the Offset Value of the shadow to offset the negative value to the inverse direction in the positive direction of the x y axis.
V1.shadowoffset = cgsizemake (2, 2 );
// Set the shadow color
V1.shadowcolor = [uicolor yellowcolor];
// Label text color
V1.textcolor = [uicolor redcolor];
// Label text size
// (1) Font Style
// (2) font size (17 by default)
// Systemfontofsize: default system font. You can change the font size.
V1.font = [uifont systemfontofsize: 25];
V1.font = [uifont fontwithname: @ "thonburi-bold" Size: 20];
/// Uifont familynames
// Nslog (@ "% @", [uifont familynames]);
/// Uifont fontnamesforfamilyname: @ "thonburi" Get the font name of the corresponding font
// Nslog (@ "% @", [uifont fontnamesforfamilyname: @ "thonburi"]);
[_ View addsubview: V1];
[V1 release];
}
Control setting properties (uibutton, uitextfield)