This article simply lists some common UI controls and their unique properties, events, and so on. Because it's a note, it's less detailed than it is.
UIView
All UI controls inherit from this UIView, which has properties that are owned by all controls, which are the simplest and most general properties of the control.
- Enable: whether it is enabled;
- Selected: whether to be selected;
- Contentverticalaligement: Content is the vertical alignment, it is an enumeration, respectively, there are uicontrolcontentverticalaligementcenter/top/bottom/fill;
- Contenthorizontalalignment: Content is the horizontal alignment, it is an enumeration, uicontrolcontenthorizontalaligmentcenter/left/right/center;
- Hidden: Show or hide, bool type;
- Frame: A structure that determines the size and position of a control, which may not work with forstate.
OC does not allow you to directly modify the members of the object's struct properties, but you can modify the properties of the struct by declaring the other struct to modify the value inside the struct and then resetting the value of the object's struct property.
event Action , here's how to bind an event to a control in the form of code.
[MyControl addtarget:self Action: @selector (myactionmethodname:) forcontrolevents: event Name];
[MyControl removetarget:self Action: @selector (myactionmethodname:) forControlEvents: event Name];
If more than one event is involved, you can use the logical or "| |" Merged together.
- Get all the methods that have registered events for the control: Nsset *myactions=[mycontrol alltargets];
- Get all the methods that the control has registered for this event: Nsarray *myactions=[mycontrol actionfortarget: event Name];
For the parameters of most events, the first is the control that triggers the event, the type is the ID, and after binding the event with a code-bound event or through a storyboard line, you can change the type of the ID to the type of the control itself, so that you do not have to cast when the control is used back inside the method.
At the end of the event section, catch a common event and click event UIControlEventTouchUpInside.
UIButton
To create a button by style,
UIButton *btn= [UIButton buttonwithtype:uibuttontyperoundedrect];
There are several types of styles:
- Uibuttontypecustom, custom style;
- Uibuttontyperoundrect, white rounded rectangle, this is the default;
- Uibuttontypedetaildisclosure: Blue Disclosure button, no text;
- Uibuttontypeinfolight: Small Circle Information button for widgets; (the background of the button is white by default, and the color of the page has been changed to light blue)
- Uibuttontypeinfodark: A button with a shrine circle in the background;
- Uibuttontypecontactadd: Blue Plus "+" button;
Common Properties:
- Title: The contents of the button;
- Image: The picture of the button;
- Titlecolor: The color of the button content;
- Shadowcolor: The color of the shaded part of the button;
- BackgroundImage: Background image of the button;
The values of the above properties are set as follows
[Btn settitle:@ "Button1" forstate: ...]; [Btn setimage:[uiimage imagename:@ "picture filename"] forstate: ...]; [btn Settitlecolor:[uicolor Redcolor] forstate: ...]; [btn Setshadowcolor:[uicolor Redcolor] forstate: ...]; [BNT setbackgroundimage:[uiimage imagenamed:@ "picture filename"] forstate];
This property is set with Forstate, which means that this property is only valid in a certain state, and the button has the following four states: Uicontrolstatenormal,uicontrolstatehighlighted, Uicontrolstatedisabled,uicontrolseleted.
Setting the background color of the button does not require the color of the button, only according to the original property settings can be: Btn.backgroundcolor=[uicolor Clearcolor];
UILabel
The label is a very simple and easy control, and here is a list of some of its properties
- Text: textual content;
- TextColor: The color of the text;
- TextAlignment: horizontal alignment, because I study is iOS6, many of the information found on the Internet is an earlier version, not the same, this need to enumerate, in the iOS6 later version, this property is the nstextalignment type;
Nstextalignmentleft,nstextalignmentcenter,nstextalignmentright,nstextalignmentjustified,nstextalignmentnatural
The iOS5 and earlier versions are uitextaligenment, and its values are
Uitextalignmentleft,uitextalignmentcenter,uitextalignmentright;
- Linebreakmode: This property is more important, is to control the way the word is wrapped, it is an enumeration of the Nslinebreakmode type
Nslinebreakbywordwrapping,//In the Word display units display, the latter part of the omission does not show nslinebreakbycharwrapping,//display units in the display unit, the latter part of the ellipsis does not show Nslinebreakbyclipping,//Cut the content length with the same width as the text, and the latter part is deleted. Nslinebreakbytruncatinghead,///Front part of the text with ... method is omitted, displaying the trailing text content. Nslinebreakbytruncatingtail,//The end of the content with ... Method omitted to display the text content of the header. nslinebreakbytruncatingmiddle//The middle of the content with ... The method is omitted, showing the text content of the kinsoku.
- NumberOfLines: Control whether the content is displayed in multiple lines, if 0 is multiple lines;
Uiimageview
This is for the picture display of the control, by setting the Image property to display the picture, in OC, the picture is the UIImage type, this type in the UIButton section has also been used to set the button's picture and button background, but to get this picture, there are three ways:
The first thing is to add resources to the project: "Project name-info.plist" file in the project right-click "AddFiles ..." to add the picture resource to the project. The following code will then be able to get to the picture normally
UIImage *img=[uiimageimagenamed:@ "1.jpg"];
Otherwise, if you simply drag and drop like Xcode inside, run the time is not to see the picture.
nsurl*url=[nsurlwrithstring:@ "Http://www.baidu.com/img/bdlogo.png"]; UIImage *img=[[uiimage Alloc]iniwithdata:[nsdata Datawithcontentsofurl:url];
NSString *path=[nsstringstringwithformat:@ "%@/documents/%@.jpg", nshomedirectory,@ "test"]; UIImage *img=[[uiimage Alloc]initwithcontentsoffile:path];
Common Properties
Contentmode: How the picture is displayed, which is an enumeration type,
Uiviewcontentmodescaletofill, Uiviewcontentmodescaleaspectfit, Uiviewcontentmodescaleaspectfill, Uiviewcontentmoderedraw, Uiviewcontentmodecenter, uiviewcontentmodetop, Uiviewcontentmodebottom, Uiviewcontentmodeleft, Uiviewcontentmoderight, uiviewcontentmodetopleft, uiviewcontentmodetopright, Uiviewcontentmodebottomleft, Uiviewcontentmodebottomright,
In the above enumeration values without scale, there is one common denominator is that when the picture size exceeds the size of the control, only a portion of the picture is displayed, and the excess is not displayed. And there are three enumerations to be specific.
Uiviewcontentmodescaletofill the picture will deform (the aspect ratio of the picture is changed), the picture will be displayed in the control;
Uiviewcontentmodescaleaspectfit: The proportions of the picture are the same, fill the control as much as possible, fill the control with the shortest side, and the unfilled part will have filler;
Uiviewcontentmodescaleaspectfill: The proportions of the picture are the same, the image will be filled with the longest side of the control, there will be a part of the display does not come out;
- Center: The property of the central point location of the space, which can be set by setting this value to change the position of the control, which is the Cgpoint type, which can be constructed by Cgpointmake (cgfloat x,cgfloat y);
- Transform: Assigning different values, the image will be changed on the basis of the original
- Cgaffinetransformmaketranslation (cgfloat dx,cgfloat dy);//move dx,dy pixels to the positive direction of the X, Y axis respectively;
- Cgaffinetransformmakerotation (cgfloat angle);//angle radians rotated clockwise in the center of the control;
- Cgaffinetransformmakescale (cgfloat scale_w,cgfloat scale_h);//scale scale_w and scale_h times respectively by the original width and height;
- Highlightedimage: A picture that is displayed when the control is in a highlighted state;
- Highlighted:bool property of type, controls whether the control is in the highlighted state
Uitextfield
This is a text box, relatively a simple control, slightly more complicated than Uilabel.
- text:nsstring type, text content within the textbox;
- Placeholder:nsstring type, content that appears in the text box when there is no content in the text box;
- Securetextentry:bool type, whether the text box content is displayed in the form of a password;
- Returnkeytype: Pop-up soft keyboard, enter the place to show the type of key, respectively, the following type;
Uireturnkeydefault, Uireturnkeygo, uireturnkeygoogle, uireturnkeyjoin, Uireturnkeynext, Uireturnkeyroute, Uireturnkeysearch, uireturnkeysend, Uireturnkeyyahoo, Uireturnkeydone, Uireturnkeyemergencycall,
- Keyboardtype: The type of soft keyboard that pops up, altogether has the following these types
Uikeyboardtypedefault, uikeyboardtypeasciicapable, uikeyboardtypenumbersandpunctuation, Uikeyboardtypeurl, Uikeyboardtypenumberpad, uikeyboardtypephonepad, Uikeyboardtypenamephonepad, uikeyboardtypeemailaddress, Uikeyboardtypedecimalpad, Uikeyboardtypetwitter, uikeyboardtypewebsearch, Uikeyboardtypealphabet = uikeyboardtypeasciicapable;
- Clearbuttonmode: The display time of the fork that clears the content in the text box
Is the red box in the figure, this enumeration has the following values
Uitextfieldviewmodenever, uitextfieldviewmodewhileediting, uitextfieldviewmodeunlessediting, Uitextfieldviewmodealways
Method
If the text box is in the edit state, the soft keyboard will pop out, and if you want to close the soft keyboard, you can call the following method
[Txtbox Resignfirstresponder];
Event
For text boxes, you can trigger different events before or after editing, or you can trigger events when values change, as listed below
textdidbeginediting;//triggers when textdidendediting;//is triggered when the textdidchange//content changes when the edit is triggered when the edit is started
Category: IOS
iOS Base controls