Common Properties for iOS development-ui controls

Source: Internet
Author: User
Tags uikit

I. Overview

In the process of running the program, we often have to change the display state of the control, such as the download progress, the player's progress, the image zoomed out and so on, then how to modify it?

Two. Modifying the state of a UI control

Each UI control is an object, and to modify the state of the object is to modify the object's properties, such as modifying the text of the Uilabel display to modify the Uilabel's Text property

@interface Uilabel:uiview <NSCoding> @property (nonatomic,copy)   nsstring           *text;            Default is Nil@end

Modify the button's background image to modify the UIButton ImageView property

1 @interface Uibutton:uicontrol <NSCoding>2 @property (nonatomic,readonly, retain) Uiimageview *  ImageView  Ns_available_ios (3_0); 3 ... 4 @end

As a result, there are a number of UI controls that have their own specific properties, but there are properties that each UI control has, such as the location and dimensions, the parent control's child controls, and so on, so that the public properties are extracted into UIView, and all the controls inherit from UIView.

Three. Uikit coordinate system

In Uikit, the origin of the coordinate system (0,0) is in the upper-left corner, the X-value extends to the right, and the Y-value extends downward.

Three. Common Properties of UIView

1. Get your own parent control object.

@property (nonatomic,readonly) UIView      *superview;
2. Get your own child controls, the child controls are stored as an array, and the first one to add is array 0.
@property (nonatomic,readonly, copy) Nsarray *subviews;

NSLog (@ "%ld child control \ n", Self.view.subviews.count), and a result of 2 button2 is a child control that is a green control. 3. The id\ of the control identifies that the parent control can be distinguished by tag and can be assigned to the right.
@property (nonatomic,readonly, copy) Nsarray *subviews;
Use of Tag:
-(Ibaction) Click: (UIButton *) but{NSLog (@"the button was clicked \ n"); if(But.tag = = A) {NSLog (@"the button above was clicked \ n"); }    Else if(But.tag = = to) {NSLog (@"the button below has been clicked \ n"); } NSLog (@"%ld\n", But.tag);}

4. The deformation properties of the control (you can set the rotation angle, scale, and other properties)

@property (nonatomic) Cgaffinetransform transform;  
1 indicates the state of the control's deformation (rotation angle, scale, etc.) 2 Create a function of the Cgaffinetransform type data this property requires Cgaffinetransform type data and a common function for creating this type of data
// creates a scaling ratio of SX and SY for an X, y direction cgaffinetransform Cgaffinetransformmakescale (cgfloat sx, CGFloat sy) // On the basis of the original deformation value T, the expansion ratio of x, Y direction is the deformation of SX and Sy. cgaffinetransform Cgaffinetransformscale (Cgaffinetransform t,  cgfloat SX, cgfloat sy)//  Create a deformation value cgaffinetransformmakerotation (cgfloat angle) with a rotational angle of angle On the basis of the original deformation value T , the rotation cgaffinetransformrotate (Cgaffinetransform t, cgfloat angle) in the angle angle is performed;

Empty previous deformation properties

_btn.transform = cgaffinetransformidentity;

5. The position and dimensions of the control (in the upper-left corner of the parent control as the origin of the coordinates), the coordinates of the upper-left corner

@property (nonatomic) cgrect frame;

6. Position of the midpoint of the control (in the upper-left corner of the parent control as the origin of the coordinates)

@property (nonatomic) Cgpoint Center;

7. The position and dimensions of the rectangle where the control is located (the origin of the coordinates in its upper-left corner, so the bounds x\y is generally 0)

@property (nonatomic) cgrect bounds;

Five. Common methods of UIView

1. Add a child control view

-(void) Addsubview: (UIView *) view; 2. Remove-(void) Removefromsuperview from the parent control;

3. Find the corresponding control (usually child controls) based on a tag ID

-(UIView *) Viewwithtag: (nsinteger) tag;

Common Properties for iOS development-ui controls

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.