Uibuttona. Material preparation 1. Picture material placed in images.xcassets B. Button State 1.normal: Default state for the enumeration constant corresponding to the: UIControlStateNormal 2. Highlighted (when highlighted) button is pressed (not released) the corresponding enumeration constant: uicontrolstatehighlighted 3.disabled (Invalid state, unavailable) if the Enable property is no, is in the disabled state, which means that the button cannot be clicked to the corresponding enumeration constant: uicontrolstatedisabled C. Button Property Type: Change to custom, clear the transparent effect of the background when the button is pressed state Config: Select button states, In turn, set other properties of the button in different states D.autolayout automatic layout AutoLayout interferes with the manual layout encoding of the run E. Using tag tags to combine multiple buttons with one method
1-(Ibaction) Move: (UIButton *) Sender {2CGRect Tempframe =Self.head.frame;3 4CGFloat Delta =Ten;5 Switch(Sender.tag) {6 Case 1:7 {8TEMPFRAME.ORIGIN.Y-=Delta;9 Break;Ten } One Case 2: A { -Tempframe.origin.x + =Delta; - Break; the } - Case 3: - { -TEMPFRAME.ORIGIN.Y + =Delta; + Break; - } + Case 4: A { atTempframe.origin.x-=Delta; - Break; - } - default: - Break; - } in -Self.head.frame =Tempframe; to}F. Use center and bounds to modify position, size use center to change the position, the effect and use frame almost use bounds to change the size, can change the size of the center base G. Position move Animation//Start animation
[UIView Beginanimations:nil Context:nil]; [UIView Setanimationduration:1]; (position change code) ...//Commit animation [UIView commitanimations]; H. Manual Code Creation button//1. Creating a custom button
UIButton *button = [UIButton buttonwithtype:uibuttontypecustom];
2. Add a picture
[Button Setimage:[uiimage Imagenamed:imagename] forstate:state];
3. Setting the size, position
Button.frame = rect; 4. Set tag, tag is best not to use 0, because the default is all 0, there will be confusion error, using viewwithtag:0 to get the current control, not the child control Button.tag = [[Buttondic objectforkey:@ "tag"] Intvalue];
5. Tap the Monitor button
[Button addtarget:self action: @selector (moveimage:) forcontrolevents:uicontroleventtouchupinside];
6. Add button [Self.view Addsubview:button];
Basic use of [iOS base Control-2] button