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 "ViewController.h" 2 3 @interfaceViewcontroller ()4 5@property (Weak, nonatomic) Iboutlet UIButton *Headimageview;6 7 @end 8 9 @implementationViewcontrollerTen One //in OC, the first parameter of the majority of the control's listener methods is the control itself A //-(Ibaction) Left: (UIButton *) button { - // - //NSLog (@ "----"); the //} --(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 Properties ACGRect rect =Self.headImageView.frame; at //2. Modifying struct members -RECT.ORIGIN.Y-= -; - //3. Set the structure properties of an object -Self.headImageView.frame =rect; -}
(2)
1 #import "LFViewController.h" 2 3 /** 4 using git 5 6 1. When creating a project, tick git 7 2. After the development is over, select "Source Control" "Commit" and write the comment 8*/ 9 Ten One //An enumeration type is essentially an integer that is used to replace the magic number A //enumeration type, after the first integer is specified, the subsequent number is incremented -typedefenum - { theKmovingdirtop =Ten, -Kmovingdirbottom, -Kmovingdirleft, -Kmovingdirright, +} kmovingdir; - + #defineKmovingdelta 50 A at @interfaceLfviewcontroller () - -@property (Weak, nonatomic) Iboutlet UIButton *Headimageview; - - @end - in @implementationLfviewcontroller - to-(Ibaction) Move: (UIButton *) button + { - //CGRect rect = self.headImageView.frame; theCgpoint p =Self.headImageView.center; * $ //Magic Number Magical numbers, when other programmers see the code, they don't know what it means.Panax Notoginseng Switch(Button.tag) { - CaseKmovingdirtop: theP.Y-=Kmovingdelta; + Break; A CaseKmovingdirbottom: theP.y + =Kmovingdelta; + Break; - CaseKmovingdirleft: $p.x-=Kmovingdelta; $ Break; - CaseKmovingdirright: -p.x + =Kmovingdelta; the Break; - }Wuyi the[UIView Beginanimations:nil context:nil]; -[UIView setanimationduration:1.0]; Wu -Self.headImageView.center =p; About $[UIView commitanimations]; - } - --(ibaction) Zoom: (UIButton *) button A { +CGRect rect =self.headImageView.bounds; the - //in the C language, the judgment about bool: nonzero is true $ if(Button.tag) { theRect.size.width + = -; theRect.size.height + = -; the}Else { theRect.size.width-= -; -Rect.size.height-= -; in } the the //Animation About //beginanimations indicates that subsequent code will "participate in" the animation the[UIView Beginanimations:nil context:nil]; the[UIView setanimationduration:2.0]; the +Self.headImageView.bounds =rect; - //self.headImageView.alpha = 0; the Bayi //Commitanimations, commits and generates animations for all animations after BeginAnimation the[UIView commitanimations]; the } - - @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----a button base for the UI Foundation