"Objective-c Study record" sixth day

Source: Internet
Author: User
Tags transparent color

Learning the UI part of the content today, a bit more, well organized.

The first is UIWindow.

Direct instantiation of UIView: UIView *view = [[UIView alloc] init];

Then set it to size: View.frame = CGRectMake (10,30,355,627); Learn HTML or interface aspects of this rect, as the name implies is a rectangle rect (x,y,width,height). x represents the horizontal axis of the rectangle, y represents the vertical axis of the rectangle, width represents the width of the rectangle, height represents the height of the rectangle, and with these four parameters, we can identify a window on the iphone. We are in the life of the axis is generally the lower left corner, the right x axis increment, up the y axis, and the computer screen is calculated from the upper left corner, that is, the right x-axis increment, the downward y-axis increment. Here the size of this rectangle, four weeks 10px from the edge of the screen on the IPhone6, as for why the y-axis direction offset 30px, because the IOS notification bar accounted for 20px, and the notification bar is very high priority.

Now we still can't see anything on the simulator, because we only instantiate this window, not yet set its color: View.backgroundcolor = [Uicolor Yellowcolor];

Finally, add this window as a subclass of the entire form: [Self.view Addsubview:view];

Next is some attributes/parameters that need to be remembered:

  Frame

View.frame.origin.x-view offset from screen x, 10px

View.frame.origin.y-view offset from screen y, 30px

The width of the View.frame.size.width-view

View.frame.size.height-view's High

  Bounds

(View.bounds.origin.x, VIEW.BOUNDS.ORIGIN.Y, View.bounds.size.width, View.bounds.size.height)

Bounds represents the size of the view border, whose x and Y are always equal to 0,width, height and frame, and to some extent frame can be used instead of bounds.

  Center

(VIEW.CENTER.X,VIEW.CENTER.Y)-center point of the screen

Get screen resolution UIScreen:

[[UIScreen Mainscreen]bounds].size.width

[[UIScreen Mainscreen]bounds].size.height

Forms also have the concept of child-parent, which is nested in the parent view, similar to the <div><div></div></div> in HTML, where one child view can have only one parent view, and a child view may have multiple. The hierarchical relationship of views is summarized as: 1. When you are in the same parent view, the view that is added first is overwritten below; 2. The child view is obscured by the parent view, and the child view of the parent view is obscured if the parent view level is lower than the other sibling views.

The first is to assign its parent view to a view: UIView *superview = View.superview;

Or add its child view to the parent view in another way: [Superview addsubview:view2]; [Superview ADDSUBVIEW:VIEW3];

We can then iterate over the parent view, where the enumeration traversal is used:

Nsarray *subviewsarray = superview.subviews;

For (UIView *view in Subviewsarray)

Todo

You can also set a label for the view so that we can find the view through the tag, which is somewhat similar to the tag in unity: View.tag = 1; get view According to tag : UIView *view = [Superview viewwithtag:1];

Swap views.

Rule: 1. When swapping views of two layers , the correct number of layers must be filled in; 2. After swapping two layers, the array subscript for the corresponding sub-view also changes.

[Superview exchangesubviewatindex:0 withsubviewatindex:1]; If the hierarchy does not exist, the interchange is not valid.

To insert a view into a specified layer:

[Superview Insertsubview:view belowsubview:view2];

Put a view in the top/bottom level

[Superview Bringsubviewtofront:view];

[Superview Sendsubviewtoback:view];

Next is the adaptive content:

The first thing to do is to set the Allow view adaptive: View.autoresizessubviews = YES;

Then you can set the adaptive way: View.autoresizingmask = uiviewautoresizingflexiblewidth; Here are a few options: Uiviewautoresizingflexibleheight not listed, simple is the right and left up and down wide and high self-adaptation.

The second is Uilabel.

The label is similar to view, first instantiated: UILabel *label = [[UILabel alloc] init];

Set Size: Label.fram = CGRectMake (10,100,350,300);

Set color: Label.backgroundcolor = [Uicolor Bluecolor];

Setting content: Label.text = @ "Hello IOS";

Layout mode: label.textalignment = Nstextalignmentcenter;

Text color (two ways): 1.label.textcolor = [Uicolor Greencolor]; there is a special clearcolor that shows the transparent color

2.label.textcolor = [Uicolor colorwithred:0.1 green:0.8 blue:0.2 alpha:1]; set color by RPGA

Font settings: Label.font = [Uifont systemfontofsize:25];25 is font size

Label.font = [Uifont boldsystemfontofsize:25];

Label.font = [Uifont italicssystemfontofsize:25];

And you can see all the fonts in the system:

For (NSString *name in [Uifont Familynames])

NSLog (@ "%@", name);

Label.font = [Uifont fontwithname: @ "Apple Color Emoji" size:25];

Font Shadow: Label.shadowcolor = [Uicolor Redcolor];

Label.shadowoffset = Cgsizemake (5,5);

line break mode : Label.linebreakmode = nslinebreakbycharwrapping; wrapping according to characters

Label.numberoflines = 10; Set the number of rows displayed

Calculates the label size based on the string size:

Cgsize size = [Label.text sizeWithFont:label.font constrainedtosize:cgsizemake (355,1000) Linebreakmode]: Nslinebreakbycharwrapping];

Finally, UIImage.

This loads the picture using a local image.

First you need to set the path of the picture, because the picture is placed in the directory of this project, so we need to get the path of the project first: NSString *path = [[NSBundle mainbundle] resourcepath];

Then set the picture path: nsstring *imagepath = [NSString stringwithformat:@ "%@/bg.png", path];

Read the picture according to the path: UIImage *image = [[UIImage alloc] initwithcontentsoffile:imagepath];

After reading the picture can not display, need to use a vector to load the picture, so you need to instantiate a Picture object: Uiimageview *imageview = [[Uiimageview alloc] initwithimage:image];

Finally set the size, but also can set the background color: Imageview.frame = CGRectMake (10,100,300,300);

Imageview.backgroundcolor = [Uicolor Yellowcolor];

content format : Imageview.contentmode = uiviewcontentmodescaletofill;//Stretch fills the entire carrier

Imageview.contentmode = uiviewcontentmodescaleaspectfill;//Stretch does not change proportions, fills the longer side

Imageview.contentmode = uiviewcontentmodescaleaspectfit;//Stretch does not change proportions, fills the shorter side

Play sequence frame animations :

Frame animation is a common form of game animation in 2D games, the principle is that we saw the flip-page animation, through the constant replacement of the displayed pictures, resulting in visual dynamic effect. First, a set of pictures of the frame animation, Count, named "Png$.png" imported into the project directory.

It then uses an array to store the images: nsmutablearray *imagearray = [[Nsmutablearray alloc] init];

for (int i = 1;i <= count;i++)

{

UIImage *image = [UIImage imagenamed:[nsstring stringwithformat:@ "Png%d.png", I]];

[Imagearray Addobject:image];

}

Then play through a picture carrier: uiimageview *imageview = [[Uiimageview alloc] init];

Set Size: Imageview.frame = CGRectMake (10,10,300,300);

Add to Parent view: [Self.view Addsubview:imageview];

You can also set the background color: Imageview.backgroundcolor = [Uicolor Yellocolor];

Next is the more important setting:1. Specify the sequence animation picture to play: Imageview.animationimages = Imagearray;

              2. Set the length of time to play: Imageview.animationduration = 3;

              3. Set the number of plays: Imageview.animationrepeatcount = 5;

"Objective-c Study record" sixth day

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.