ui-2-uilabel&uiimageview-Supplement

Source: Internet
Author: User

Course Highlights:

    • The inheritance relationship between controls,
    • UILabel
    • Uiimageview
    • Implementing frame Animations with Uiimageview
    • Add

An attempt to inherit a relationship between

When I learned UIView yesterday, I learned that there are several common properties in UIView:

* backgroundcolor: Background color

* Alpha: Transparency

* subviews: The child tries to assemble

* Hidden: whether to hide

* Tag: Tag value

* Superview: The father tried to

from these basic attributes, we can find that there are no attributes in the UIView that are shown in the attempt above, that is to say UIView this attempt can not meet our needs. At this time Uilabel was born. Before we delve into Uilabel, we need to look at the relationship between UIView and Uilabel.

[Self.window makekeyandvisible];      

// first, follow the three steps we created to create a uilbale, and put him on the window. UILabel *testlabel = [[UILabel alloc]init]; // Press and hold the command while the mouse clicks on the frame, we can see the API about the Frame property testlabel.frame = CGRectMake ); [Self.window Addsubview:testlabel];

The main reason for this is that uilable inherits from UIView, and because Uilabel and UIView have many common properties, the Uilabel class of the system takes inheritance directly, avoiding the property of writing duplicates in Uilabel.

PS: In engineering, how do we see who the Uilabel class is inherited from? Press and hold command while clicking on the class name. The system automatically navigates to the interface portion of the class's. h file, and the colon is the part that indicates who the class inherits from. Learn how to view APIs and get used to viewing APIs in the process of doing projects

UILabel: He is a label trying to inherit UIView, not fit to put too much text content.

    //first create a Uilabel objectUILabel *testlabel =[[UILabel alloc]init]; //setting the location and size of the TestLabelTestlabel.frame = CGRectMake ( -, -, -, -); //set the background color of TestLabelTestlabel.backgroundcolor =[Uicolor Graycolor]; //set string to TestLabelTestlabel.text =@"the world's leading mobile device operating system"; //set font color for TestLabelTestlabel.textcolor =[Uicolor Greencolor]; //give TestLabel a way to set it upTestlabel.textalignment =Nstextalignmentcenter; //set font size for TestLabelTestlabel.font = [Uifont systemfontofsize: -]; //set shadow color for TestLabel//Testlabel.shadowcolor = [Uicolor blackcolor]; //Set the shadow offset for TestLabel you can try this at this time if you fill in ( -5,-5) what effect//Testlabel.shadowoffset = Cgsizemake (10, 10); //set the number of rows to TestLabel 1 is a line display 2 is two lines display 0 is based on the content of the adaptive functionTestlabel.numberoflines =2; //automatically set the font size based on the width of the TestLabel, so that the content is all displayedTestlabel.adjustsfontsizetofitwidth =YES; [Self.window Addsubview:testlabel];

Uiimageview: Image attempted, inherited UIView, mainly used to display pictures

How to put pictures in the project

 //Create an attempt objectUiimageview *imgview =[[Uiimageview alloc]init]; //If the picture is in PNG format, the image name does not need to be suffixed, otherwise the suffix will be added .Imgview.image = [UIImage imagenamed:@ "picture name"];    //in a certain direction to make the picture adaptive, has achieved the best look at the effect. Imgeview.contentmode =Uiviewcontentmodescaleaspectfit; //Let the picture fill the frameImgeview.contentmode =Uiviewcontentmodescaletofill; //take the corresponding position of the picture and put it on the screen, will go beyond the set of pictures to try frameImgeview.contentmode =Uiviewcontentmoderight; //cut out the part that's beyond the frame you're trying toImgeview.clipstobounds =YES; //to try to set the frameImgview.frame = CGRectMake (Ten,Ten, -, -); //will try to put it on the window[Self.window Addsubview:imgview];

Set up a frame animation with Uiimageview

  /** Create a frame animation four elements 1, set the interval time 2, prepare the picture footage 3, set the number of repetitions 4, start animation 5, end the animation*/            //Animationduration to set the animation time intervalImgview.animationduration =1; UIImage*IMG1 =[UIImage imagenamed:@ "image name"]; UIImage*img2 = [UIImage imagenamed:@"Picture name"]; Nsarray*array =@[img1,img2]; //preparing footage for frame animationsImgview.animationimages =Array; //set the number of repetitions for an animationImgview.animationrepeatcount =0; //Start Animation[Imgview startanimating]; //End Animation[Imgview stopanimating]; The difference between Ps:uiimageview and UIImage, Uiimageview he is like a special place to put the picture, UIImage object is the picture you want to place. 

Add

#import "AppDelegate.h"/** Macro definition Format: #define K constant Name @ "" * Role: Macro definition is to replace the variable name with the content, not only can replace the string can also replace a code * naming rules: K + Hump naming law, for example: Kcotent*/////#defineKcontent @ "What I have Changed"#defineKlabelx label.frame.origin.x#defineKscreenwidth [UIScreen mainscreen].bounds.size.height@interfaceappdelegate ()@end@implementationappdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {#pragmaMark Supplements/** Delay Method Performselector * Cgrectgetheight (< #CGRect rect#>) * [UIScreen Mainscreen].boun DS.ORIGIN * Macro Definition * Usage tips for macro definitions*/[Self.window makekeyandvisible]; //delay how many seconds to execute the corresponding method, the method selected with selector must be implemented, otherwise it will crash. [Self performselector: @selector (start) Withobject:nil Afterdelay:5]; UILabel*label =[[UILabel alloc]init]; Label.frame= CGRectMake (Ten, -, -, the); Label.backgroundcolor=[Uicolor Redcolor]; Label.text= Kcontent;//at this point, use the macro definition and try to press and hold the command while clicking Kscreenwidth[Self.window Addsubview:label];//gets the X-value way to the label//    //The first way//NSLog (@ "label x=%f", Klabelx);//    //The second way (this way can also get to the far right of the space in the middle of the X value, try to see how Uilabel is inherited from which class to see how to get to the label height, width)//NSLog (@ "label x=%f", Cgrectgetminx (Label.frame)); //UIScreen refers to the screen, can help the group we get to various screen width and height, again I use macro definition to getNSLog (@"High =%f of the screen", Kscreenwidth); returnYES;}- (void) start{}

ui-2-uilabel&uiimageview-Supplement

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.