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