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
1. Normal (normal state)
Defaults (default)
The corresponding enumeration constants: UIControlStateNormal
2, highlighted (highlight state)
When the button is pressed (the finger is not released)
The corresponding enumeration constants: Uicontrolstatehighlighted
3, disabled (failure status, unavailable status)
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)
#import "LFViewController.h"@interfaceLfviewcontroller () @property (weak, nonatomic) Iboutlet UIButton*Headimageview;@end@implementationLfviewcontroller//in OC, the first parameter of the majority of the control's listener methods is the control itself//-(Ibaction) Left: (UIButton *) button {// //NSLog (@ "----");//}-(ibaction) move{//change the head position by frame//in OC, you are not allowed to directly modify the members of the struct properties of the object//allows you to modify the struct properties of the object//1. Remove Structure PropertiesCGRect rect =Self.headImageView.frame; //2. Modifying struct membersRECT.ORIGIN.Y-= -; //3. Set the structure properties of an objectSelf.headImageView.frame =rect;}
(2)
#import "LFViewController.h"/** using git 1. When creating a project, tick git 2. After the development is over, select "Source Control" "Commit" and write a comment*///An enumeration type is essentially an integer that is used to replace the magic number//enumeration type, after the first integer is specified, the subsequent number is incrementedtypedefenum{kmovingdirtop=Ten, Kmovingdirbottom, Kmovingdirleft, Kmovingdirright,} kmovingdir;#defineKmovingdelta 50@interfaceLfviewcontroller () @property (weak, nonatomic) Iboutlet UIButton*Headimageview;@end@implementationLfviewcontroller-(Ibaction) Move: (UIButton *) button{//CGRect rect = self.headImageView.frame;Cgpoint p =Self.headImageView.center; //Magic Number Magical numbers, when other programmers see the code, they don't know what it means. Switch(Button.tag) { Casekmovingdirtop:p.y-=Kmovingdelta; Break; Casekmovingdirbottom:p.y+=Kmovingdelta; Break; Casekmovingdirleft:p.x-=Kmovingdelta; Break; Casekmovingdirright:p.x+=Kmovingdelta; Break; } [UIView Beginanimations:nil context:nil]; [UIView setanimationduration:1.0]; Self.headImageView.center=p; [UIView commitanimations];}-(ibaction) Zoom: (UIButton *) button{CGRect rect=Self.headImageView.bounds; //in the C language, the judgment about bool: nonzero is true if(Button.tag) {rect.size.width+= -; Rect.size.height+= -; } Else{rect.size.width-= -; Rect.size.height-= -; } //Animation//beginanimations indicates that subsequent code will "participate in" the animation[UIView Beginanimations:nil Context:nil]; [UIView setanimationduration:2.0]; Self.headImageView.bounds=rect;//self.headImageView.alpha = 0; //Commitanimations, commits and generates animations for all animations after BeginAnimation[UIView commitanimations];}@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