iOS Stage Learning 26th Day notes (Uilabel's introduction)

Source: Internet
Author: User
Tags set background

iOS Learning (UI) Knowledge Point Grooming

First, about the use of Uilabel introduction

1) Concept: Uilabel is a control that inherits from UIView for displaying textual information

2) All controls in the UI inherit from UIView that is UIView is the ancestor class of the UI.

3) uilable instantiation mode code:

1UILabel *label=[[uilabel Alloc]init];//Initialize Uilabel2label.text=@"Hello,kingkong";//assign a value to a label text content3Label.backgroundcolor=[uicolor Blackcolor];//set lable background color to black4[Label Settextcolor:[uicolor Whitecolor];//set text font color to white5Label.font=[uifont systemfontofsize:15.0];//set the label font size6Abel.frame=cgrectmake ( -, -, $, +);//set the x, y coordinates, and length and height of a label7[Self.window Addsubview:label];//mount the initialized label to the screen view

4) The view color can be set according to the RGB type, using the color extraction software to get the RGB value of the colors we want can easily set any color type
For ease of use we can write a special method code that defines the color based on RGB settings as follows:

1  #define Colorwithrgb (R,g,b) ([Uicolor colorwithred:r/255.0 green:g/255.0 blue:b/255.0 alpha:1])


5) We can also set the style instance code of the control via nsmutableattributedstring:

1UILabel *label=[[uilabel Alloc]init];//Initialize Uilabel2  //initializing the Nsmutableattributedstring object3Nsmutableattributedstring *attribute=[[nsmutableattributedstring alloc]initwithstring:text];4 //set font size based on range5[Attribute Addattribute:nsfontattributename Value:[uifont systemfontofsize: -] Range:nsmakerange (0,1)];6 //Set background color based on range7[Attribute Addattribute:nsbackgroundcolorattributename Value:[uicolor Yellowcolor] Range:nsmakerange (0,1)];8 //set font color based on range9[Attribute Addattribute:nsforegroundcolorattributename Value:[uicolor Bluecolor] Range:nsmakerange (0,1)];Ten  //automatically adjusts the font size of text based on the label's width OneLabel.adjustsfontsizetofitwidth =YES; ALabel.numberoflines =0;//Maximum number of rows until content fills the label width height completely -Label.linebreakmode =Nslinebreakbytruncatingtail; -  //set text color based on RGB Here is a custom method theLabel.textcolor = Colorwithrgb (255,154,155); -  //Set Text Center -  //prior to iOS 7 Uitextalignmentcenter -Label.textalignment =Nstextalignmentcenter; +   //sets the width of the label's border -Label.layer.borderWidth =1; +  //set the color of the border ALabel.layer.borderColor =Label.textColor.CGColor; at  //Set the fillet (when the image is square, the rounded value is half the image and the image becomes a circle) -Label.layer.cornerRadius =6; -  //the shadow of the label text -Label.shadowcolor =[Uicolor Blackcolor]; -  //offset of LAEBL text -Label.shadowoffset = Cgsizemake (Ten,Ten); in //assign a set style to a control -label.attributedtext=attribute; to //Loading Controls +[Self.window Addsubview:label];


6) When we use the Custom view page without using iOS main.storyboard, we need to remove the main storyboard file base name of the info option under target
Otherwise an error will be executed.

7) When we are unable to choose the iOS simulator that is required for the project to run, locate the deployment target in the general under target and set the corresponding iOS version.

8) IOS UI project creation options are generally single View application items

9) When initializing a control object, we must first initialize the view code as follows:

1 // initializing the View object  [UIScreen mainscreen].bounds  automatically gets the size of the screen 2 self.window = [[UIWindow alloc] initwithframe:[ Uiscreenmainscreen].bounds];    3 // set the view background color 4 self.window.backgroundColor = [Uicolor whitecolor]; 5 // set the current window as the main window and show it out note: This item must be set otherwise the view cannot be displayed 6 [Self.window makekeyandvisible];

10) What is frame? The frame is the coordinate system, the first parameter is the x-coordinate, the second parameter is the y-coordinate, the third parameter is the width, and the fourth parameter is the height

1 cgrect frame = CGRectMake (0);


11) Gets the width \ height, x-coordinate, y-coordinate of the screen or view

1CGRect Mainscreenframe =[UIScreen mainscreen].bounds;2 //Get screen width3CGFloat screenWidth1 =MainScreenFrame.size.width;4 //get the width of a view5CGFloat screenWidth2 =cgrectgetwidth (self.view.frame);6 //get the height of the screen7CGFloat screenHeight1 =MainScreenFrame.size.height;8 //get the height of a view9CGFloat screenHeight2 =cgrectgetheight (self.view.frame);Ten //gets the x-coordinate of the screen OneCGFloat StartX =mainscreenframe.origin.x; A //Gets the y-coordinate of the screen -CGFloat starty = MAINSCREENFRAME.ORIGIN.Y;

PCH file Description: PCH file is a precompiled file in iOS that can be used to implement some reference to the enemy file and the method of macro definition,
This enables a global reference to be found after the PCH file is added under Target's Build Settings key
Prefix Header fill in $ (srcroot)/target name/pch file name. pch

13) necessary process for creating controls
1. Control initialization
2. Set Frame
3. Setting the background color
4. Load the control on a view
Options available
* Can I set the text?
* Can I set the text color?
* ......

iOS Stage Learning 26th Day notes (Uilabel's introduction)

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.