iOS Development UI Chapter-button Basics

Source: Internet
Author: User

1.15

1, UI development is the placement of objects, and these objects are controls
Controls, components
2, the development of non-UI features, the use of framework
3, the first step to develop the application
See what you need on the interface.
-Open Xcode, new project
SHIFT + COMMAND + N Create a new project
www.itcast.cn
4, OC in our class name is generally prefixed
NSString
Nsarray
Namespaces are often provided in other development languages in order to avoid name collisions
There is no namespace in OC, instead of a class prefix
After you create a new item, modify the Prefiex property on the right
5, the simulator needs to pay attention to
Dimensions
Rotation
-Home key
6. Icons
Mmethod
C class
7. Xcode
Shortcut keys for running: CMD + R
Compile does not run: cmd + b
End run: cmd +.

8. Addition Calculator
Drag control to set properties when the control is displayed
Text box: Uitextfield
Text Label: UILabel
Button: UIButton
-Set keyboard type, Keyboard type

9, UIView and Uiviewcontroller
All you can see is UIView.
UIView maintenance is done by Uiviewcontroller

10, if you need to listen to a control user action
Provides a method in the controller, the return value of the method is Ibaction
--Open the Assistent window, check the right button of the control
Click events is Touch up inside
--the circle to the right of the selected event, the connection method

11. Procedures for handling general applications


12. Exit the keyboard
First Responder
Two methods
1, exit the keyboard only need to set the call out the keyboard control is no longer
The first responder can
2. If the controls that bring up the keyboard are in the same uiview
Just set this UIView end edit to

13. Automatic generation of methods or properties for drag lines
--Select the control, press control
Drag into the code, pop up a dialog box
--If you need a property, do not need to modify, directly set the name can be
--If you need a method, first modify the outlet to action
Then fill in the name, set the parameters
Method with parameters, the event is triggered by first checking the
Method has an ID type parameter and will be triggered if a parameter is
The control passed in method


================
1. Steps to create a project
Build interface (see what controls are needed, drag into the control)
The appearance of the control requires setting properties
--If you need to listen to events need to drag line method
2, the method of towing line
Drag Line Properties
Drag Line method
3. Common Controls and properties
Button: UIButton
Text Tags: UILabel
Text
Text box: Uitextfield
Text
===================

14. Private extensions, classifications, informal agreements, categories
Write a class
@interface Class name ()

@end
OPTION + Chinese key + SHIFT + Left button

15. In iOS, all controls are located in the same location as the control
The point in the upper-left corner of the rectangle box is the datum

In iOS (all computer views) is the origin in the upper-left corner.
Horizontal right is x-axis positive direction
Vertical downward for y-axis positive direction

16. Simple animation
UIView provides a animation way to implement animations
[UIView Beginanimations:nil Context:nil];
Code that needs to be executed
[UIVIew commitanimations];

17. Frame
Frame is used to describe the position and size of the control
Set Origion in the Frame property to set its position
Set the size of the frame property to set it

Note: The steps to set up frame: 1, take out, 2, modify; 3, assign a value back

18. Bounds Properties and center properties can also be done to modify the size and location of the operation
Bounds only used to set the size
The data type of the Bounds property is also cgrect
Bounds's X, Y is always based on its top left corner, usually 0.
When used in general, it is used to set the width and height of the
Center is only used to set the location
Center is the central position of the control, which is the center of the rectangular area of the control

19, transform transformation, deformation, matrix transformation
Metaphor: A transformation is a control that changes from its original state to a specified state.
Btn.transform = TF1; TF1 up 100
....
Btn.transform = TF2; TF2 Left 100
If another transformation is assigned, it means that the original transformation does not work and re-
Change from the original position to the new position

Affine affine transformation

20. Creating controls with code

1.IBAction:

1> can guarantee that the method can be wired

2> equivalent to void

2.IBOutlet:

1> can ensure that attributes can be wired

3. Common errors

Setvalue:forundefinedkey:]: This class was not key value coding

The reason for the error is: the connection problem

Some suggestions for 4.XCODE5 start

Declare some methods and properties for wiring in the class extension of the. m file

5.frame\center\bounds

1> frame: Can modify position and size

2> Center: Can modify position

3> bounds: Can modify the size (X\y is generally 0)

iOS Development UI Chapter-button Basics

A simple explanation

In general, when you click on a control, the corresponding response is the button

The function of the button is more, can display the text, but also can display the picture, can adjust the internal picture and the text position at any time

Second, the button of three kinds of states

Normal (normal state)

Defaults (default)

The corresponding enumeration constants: UIControlStateNormal

Highlighted (highlight state)

When the button is pressed (the finger is not released)

The corresponding enumeration constants: Uicontrolstatehighlighted

Disabled (fail State, unavailable state)

If the Enabled property is no, it is in the disable state, which means the button cannot be clicked

The corresponding enumeration constants: Uicontrolstatedisabled

Third, the attention point

(1) from XCODE5, the picture resources are placed in the images.xcassets to manage, you can use drag and drop to add the image used in the project to the Images.xcassets

(2) Several controls share a piece of code, usually using tag.

Iv. code Examples

(1)

1 #import "LFViewController.h" 2  3 @interface Lfviewcontroller () 4  5 @property (weak, nonatomic) Iboutlet Uibutto n *headimageview; 6  7 @end 8  9 @implementation LFViewController10 11//In OC, the first parameter of the majority of the control's listener method is the control itself//-(ibaction) Left: ( UIButton *) button {////    NSLog (@ "----"),//}16-(ibaction) Move17 {//     change the position of head by frame     // In OC, you are not allowed to modify the members of the struct properties of the object directly     //allow to modify the structure properties of the object/     /1. Remove structure Properties     cgrect rect = self.headimageview.frame;23     //2. Modify struct member Rect.origin.y-     = 20;25     //3. Set the Structure property     of an object. Self.headImageView.frame = rect;27}

(2)

 1 #import "LFViewController.h" 2 3/** 4 use git 5 6 1. When creating the project, tick git 7 2. After the development is over, select "Source Control" "Commit" and write comments 8 */9 10 11//enumeration type is essentially an integer, which is used to replace the magic number 12//enum type, after the first integer is specified, the subsequent number is incremented by the type def enum14 {kmovingdirtop = 10,16 kmovingdirbottom,17 kmovingdirleft,18 kmovingdirright,19} kmovingdir ; #define Kmovingdelta 5022 @interface Lfviewcontroller () @property (weak, nonatomic) Iboutlet UIButton *hea dimageview;26 @end28 @implementation LFViewController30-(ibaction) Move: (UIButton *) Button32 {//CGRect RE ct = self.headimageview.frame;34 Cgpoint p = self.headimageview.center;35//magic number mana, when other programmers see the code, Don't know what it means. PNs switch (button.tag) {$ case kmovingdirtop:39 p.y-= kmovingdelta;40 break;              kmovingdirbottom:42 p.y + = kmovingdelta;43 break;44 case kmovingdirleft:45 p.x-= kmovingdelta;46 break;47 CAsE kmovingdirright:48 p.x + kmovingdelta;49 break;50}51 [UIView Beginanimations:nil Co ntext:nil];53 [UIView setanimationduration:1.0];54 self.headImageView.center = p;56 [UIView comm     itanimations];58}59-(ibaction) Zoom: (UIButton *) button61 {CGRect rect = self.headimageview.bounds;63 64     In the C language, the judgment about bool: nonzero is true if (Button.tag) {rect.size.width + = 50;67 Rect.size.height + = 50;68 } else {rect.size.width-= 50;70 rect.size.height-= 50;71}72 73//End animation//Beginanima     tions says the code will be "involved" in the animation [UIView beginanimations:nil context:nil];76 [UIView setanimationduration:2.0];77 78 Self.headImageView.bounds = rect;79//Self.headImageView.alpha = 0;80 Bayi//commitanimations, will BeginAnimation After all the animations are submitted and generated animation [UIView commitanimations];83}84-@end

V. Supplementary notes

1. Parameters of the Ibaction

-(Ibaction) Left: (UIButton *) button

(1) in OC, the first parameter of the most control listener method is the control itself

(2) The parameter type when the default connection is ID

(3) If you want to be in the listening method, convenient for the use of the control, you can change the type of monitoring method after connection or connection

2. Modifying the structure members of an object

In OC, you are not allowed to directly modify the members of the struct properties of the object, but allow you to modify the struct properties of the object

The member methods for modifying struct properties are as follows:

(1) Using temporary variables to record the structure properties of an object

(2) Modifying the properties of temporary variables

(3) To reset temporary variables to the structure properties of an object

3. Need to avoid magic numbers in program development (magic number)

Use enum types to avoid magic numbers in your program

(1) An enumeration type is essentially an integer that is used to replace the magic number

(2) After the first integer is specified in the enumeration type, the following number is incremented

4. Frame & Bounds & Center

1> frame can modify the object's position and size

2> bounds can modify the size of an object

3> Center can modify the position of an object

5. End-to-end animations

Beginanimations indicates that subsequent code will "participate in" the animation

[UIView Beginanimations:nil Context:nil];

Setanimationduration used to specify the duration of the animation

[UIView setanimationduration:2.0];

Self.headImageView.bounds = rect;

......

Commitanimations, commits and generates animations for all animations after beginanimation

[UIView commitanimations];

iOS Development UI Chapter-button Basics

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.