This paper mainly introduces the basic concepts and some properties of the following UIView. As for attributes, the user is followed by a detailed introduction
-Basic concepts of UIView1. What is a control?
All UI elements on the screen are called controls (there are also many books called view components) such as button (UIButton) text (UILabel) are controls
What are the common properties of a control?
Size
Position
Background color
...........
Apple extracts the common properties of the control into the parent class UIView all the controls eventually inherit from UIView UIBUtton UIView inherit from UIView
Parent control, child control
Each control is a container that can hold other controls
Inner Gizmo is a child of a large control
The large control is the parent control of the inner gizmo
Each controller (Uiviewcontroller) has a default UIView property controller that manages all other controls that are direct or indirect child controls of this view
Common Properties for 2.UIView@property (nonatomic,readonly) UIView *superview; ? Get your own? Parent Control Object
@property (nonatomic,readonly,copy) Nsarray *subviews;? Get all your own? Child control objects
@property (nonatomic) nsinteger tag;? The ID (identity) of the control, the parent control can find the corresponding child control by tag
@property (nonatomic) Cgaffinetransform transform;? The deformation properties of the control (you can set rotation, angle, scale, pan, and so on)
-(void) Addsubview: (UIView *) view;? Add a? Child control view
-(void) Removefromsuperview; ? Remove from the parent control
-(UIView *) Viewwithtag: (nsinteger) tag; ? According to? A tag ID to find the corresponding control (?). Child controls
Before we introduce the following three properties, we first need to understand the following Uikit coordinate systems:
The origin of the coordinate system in the Uikit (0,0) is in the upper-left corner X-value to the right forward-extending the Y-value downward forward.
@property (nonatomic) cgrect frame; The position and ruler of the control rectangle in the parent control (with the upper left corner of the parent control as the coordinate origin)@property (nonatomic) cgrect bounds;? The position and ruler of the control rectangle (with the upper left corner as the coordinate origin, so bounds X, Y is generally 0)@property (nonatomic) Cgpoint Center; The position of the midpoint of the control (with the top left corner of the parent control as the coordinate origin)UIView property Setting Example1.alpha: Set the transparency of the view by default to 1
1 0 // fully Transparent 2 3 1 // not transparent
2.clipsToBounds default is no when set to yew the contents and sub-views of the dimensions beyond the current view are not displayed
Self.view.clipsToBounds = YES; Content and sub-views that exceed the dimensions of the view are not displayed
3.hidden default is no view is not visible when set to Yes
1 self.view.hidden=yes; //
4.userInteractionEnabled default Yes if set to no view cannot interact with the user and cannot respond to the event
self.view.userInteractionEnabled = NO; Unable to interact with user cannot respond to events
The 5.tag default is 0 to mark the control's
Self.view.tag = 10; Mark the view as 0 for all controls marked with a default of
6.exclusiveTouch defaults to No
The meaning of Exclusivetouch is that if the UIView that is currently set up Exclusivetouch is the first responder of the entire touch event, then all of your fingers leave the screen before the other UIView is unable to accept all the touch events throughout the event cycle
7.CGRect Frame
> represents the position and dimensions of the control as the coordinate origin (0,0) in the upper-left corner of the parent control
> Modify this property to adjust the position and size of the control
8.CGPoint Center
> represents the midpoint of the control as the coordinate origin in the upper-left corner of the parent control
> Modify this property to adjust the position of the control
9.CGRect bounds
> represents the position and size of the control in its own upper-left corner as the coordinate origin position is generally (0,0)
> Modify this property to adjust the size of the control only
10.CGAffineTransform Transform
> represents the control's deformation state rotation angle scale
> Creating a Cgaffinetransform function
Cgaffinetransformmakescale (cgfloat scalex,cgfloat ScaleY);//Create an X, y direction with a scaling ratio of ScaleX, The deformation value of ScaleY cgaffinetransformmakerotation (cgfloat angle);//create a deformation value angle with a rotational angle of cgaffinetransformscale ( Cgaffinetransform T, cgfloat SX, CGFloat sy);//On the basis of the deformation value T, then the scaling, the X, y direction of the scaling ratio of SX, SY, and then return a new deformation value Cgaffinetransformrotate (Cgaffinetransform t, cgfloat angle);//On the basis of the deformation value T, rotate again, the angle of rotation is angle, and then return a new deformation value
11.superview
Returns the parent view of the current view
12.window returns the window of the current view
The Superview and window of the root view need to be noted in Viewdidload is not obtained viewdidload only when the view loading is complete, this time is not added to the window and therefore need to be in the Viewdidappear method to obtain the The view was then added to the window
Example:
-(void) viewdidload { [super viewdidload]; NSLog (@ "viewdidload-------%@", Self.view.superview); No value NSLog (@ "Viewdidload--------%@", self.view.window);//No value}-(void) Viewdidappear: (BOOL) animated{ NSLog (@ "viewdidappear-----%@", self.view.superview); Value NSLog (@ "viewdidappear-----%@", self.view.window);//value}
13.autoresizesSubviews The default is yes to indicate that the child control changes when the size of the parent control changes
14.autoresizingMask default to Uiviewautoresizingnone does not automatically scale
15.contentMode Setting content Mode
The Uiviewcontentmodescaletofill is not populated at any scale according to the original width-to-height ratio (long and wide unequal scales). This way, the view is not blank and the content can be displayed all.
The Uiviewcontentmodeaspecttofill is filled with the original length-width ratio and does not fully display the entire content. This may overflow, but the entire view will not leave a blank space.
The Uiviewcontentmodeaspecttofit is fully displayed in terms of the original length-width ratio (growth in length and width). This makes it easy to photograph or leave a blank.
16.backgroundColor background Color
Self.view.backgroundColor = [Uicolor Redcolor]; Set the background color to red
UIView common ways to add a child view
- Addsubview adding a control to a control
- Bringsubviewtofront to move a control to the front
- Sendsubviewtoback move a control to the back
- Removefromsuperview Remove the control
- Insertsubview:atindex inserting a view and specifying an index
- Insertsubview:abovesubview; Insert a view above a view
- Insertsubview:belowsubview; Insert a view below a view
- Exchangesubviewatindex:withsubviewatindex:
The use of the above attributes can be used by the reader to try each one by themselves, without remembering to know for a while I will use a few small cases to explain the usage of each attribute in depth
iOS Development UI Foundation UIView