UIButton button controls and Uitextfield input box controls, which are two of the more commonly used controls in UI development
Compared with Uilabel, Uiimageview and Uiswitch, the usage is comparatively rich.
UIButton has four states:
Normal state UIControlStateNormal//Highlight state: State when button is pressed uicontrolstatehighlighted// Checked state: Toggle through the selected property of the UIButton object uicontrolstateselected//disable state: Toggle through the Enable property of the UIButton object, Cannot accept user's Click Uicontrolstatedisabled
If you set the text, picture data in the normal state, the remaining three states also use the data
Highlight state, color burn, disable state, color dimmed
You can also set the text, pictures and other data in each state separately.
The UIButton interior contains three sub-views:
A Uilabel text label (blue)
A Uiimageview picture control (default to the left of text) (orange)
A Uiimageview background image space (below the text and picture space) (* * *)
One of the first two sub-views, you can not display the data
650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/7C/A3/wKioL1bURAfTRZqTAAA5IonZkH0479.png "title=" screen shot 2016-02-29 pm 9.11.24.png "width=" height= "123" border= "0" hspace= "0" vspace= "0" style= "width:300px;height:123px" alt= "Wkiol1buraftrzqtaaa5ionzkh0479.png"/>
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/7C/A4/wKiom1bUQ9fjqVTKAAEoAgcVaak900.png "title=" screen shot 2016-02-29 pm 9.12.32.png "width=" height= "104" border= "0" hspace= "0" vspace= "0" style= "width:300px;height:104px" alt= "Wkiom1buq9fjqvtkaaeoagcvaak900.png"/>
The setting data must indicate which state it is in:
-(void) Settitle: (NSString *) title forstate: (uicontrolstate) state-(NSString *) Titleforstate: (uicontrolstate) state- (void) SetImage: (UIImage *) image forstate: (uicontrolstate) state-(UIImage *) Imageforstate: (uicontrolstate) state-( void) SetBackgroundImage: (UIImage *) image forstate: (uicontrolstate) state-(UIImage *) Backgroundimageforstate: ( Uicontrolstate) state
Buttons are the most commonly seen elements in the interface, in order to customize the various desired button effects, often implemented UIButton subclasses
The following effects can be achieved:
1) The setting of the UIButton property is encapsulated in the constructor method
2) Remove some of your own effects
For example, remove the shadow effect when the highlight state, overriding the setter method of the highlighted property: Do nothing
3) Modify the relative position of the text label and the picture
Override the following methods:
-(CGRect) Contentrectforbounds: (CGRect) bounds-(CGRect) Imagerectforcontentrect: (CGRect) contentrect-(CGRect) Titlerectforcontentrect: (cgrect) Contentrect
Right-hand Clear button:
@property (nonatomic) Uitextfieldviewmode clearbuttonmodetypedef enum {uitextfieldviewmodenever, Uitextfieldviewmodewhileediting, uitextfieldviewmodeunlessediting, uitextfieldviewmodealways} UITextFieldViewMode ;
Left and right side view, usually placed buttons
@property (nonatomic, Strong) UIView *leftview@property (nonatomic, strong) UIView *rightview
Left and right side view display mode
@property (nonatomic) Uitextfieldviewmode leftviewmode@property (nonatomic) Uitextfieldviewmode RightViewMode
Modifying the keyboard with Inputview
@property (ReadWrite, strong) UIView *inputview
It is usually set up for a variety of selection views, such as:
Textfield.inputview = [[Uidatepicker alloc] init];
To set the toolbar on the keyboard via Inputaccessoryview
@property (ReadWrite, strong) UIView *inputaccessoryview
Various buttons are generally placed on the toolbar, such as completion, next, previous, etc.
Uitoolbar * ToolBar = [Uitoolbar alloc] Init];textfield.inputaccessoryview = Toolbar;toolbar.frame = CGRectMake (0, 0, 375, //toolbar Add button//...
This article is from the "Teacheran" blog, make sure to keep this source http://annmeng.blog.51cto.com/3321237/1746205
Uikit Framework (UIButton) and Uitextfield