iOS basic Knowledge--02

Source: Internet
Author: User

1. Add a view

Init: all objects can be called

initWithFrame: belong to UI methods for instantiating controls

2. // Set properties:Namelabel.text = @ " where is Papa going ";

// Set Alignment , Center : namelabel.textalignment= Nstextalignmentcenter;

/**

to set the font:

+ (uifont*) Systemfontofsize: (cgfloat) fontSize; Default Body

+ (uifont*) Boldsystemfontofsize: (cgfloat) fontSize; Bold Body

+ (uifont*) Italicsystemfontofsize: (cgfloat) fontSize; Italic (English only)

*/

Namelabel.font =[uifont systemfontofsize:];

3. Set Button of the Properties

set background image,image, title, must be divided into state settings

Default

When the button is clicked , it automatically switches to the highlighted state .

selected -- set button 's selected property to YES

Disabled - set the button's enabled setting is not available when no is used

DownloadButton.titleLabel.font -- Set Button font size for Chinese text

4. prevent data from being modified : immutable variables : The data of internal elements is not modifiable ; Variable groups consume more performance

5. indent command []

6. use of Xib files:

? the Xib file can be used to describe a piece of local UI interface

? loading of Xib files

? method 1

Nsarray *objs =[[nsbundle Mainbundle] loadnibnamed:@ "Czappview" Owner:nil Options:nil];

This method creates Xib and places the objects in order in the Objs in the array

(If Xib as shown in the image on the right, then Objs in the array, in turn, there will be 3 of objects: 1 a UIView , 1 a UIButton , 1 a Uiswitch )

? method 2

Bundle parameter can be a Nil , the default is Main bundle

uinib *nib = [uinibnibwithnibname:@ "Czappview" Bundle:[nsbundle Mainbundle]];

Nsarray *OBJS = [Nibinstantiatewithowner:nil Options:nil];

? in the development phase , the developer-oriented is the xib file ; When the app is loaded on the phone , Xib The file will be converted to nib file

? to arbitrarily adjust the size of the view in the xib , set the size to Freeform

Xib and the Storyboard Comparison:

? Common denominator:

? is used to describe the software interface

? are edited using the Interface Builder tool.

? different points

? Xib is lightweight and is used to describe the local UI interface

? Storyboard is a heavyweight, a multi-interface for describing the entire software, and the ability to show jump relationships between multiple interfaces

7. Common settings for UILabel:

? @property (nonatomic,copy) nsstring *text;

? text to display

? @property (nonatomic,retain) Uifont *font;

? Font

? @property (nonatomic,retain) Uicolor *textcolor;

? text color

? @property (nonatomic) nstextalignment textalignment;

? Alignment modes (such as left, center, right)

8.uifont:

? Uifont represents fonts, and common ways to create them are as follows:

?   + (uifont*) Systemfontofsize: (cgfloat) fontSize; system default font

?  + (uifont*) Boldsystemfontofsize: (cgfloat) fontSize; Bold Body

?  + (uifont*) Italicsystemfontofsize: (cgfloat) fontSize; Italic Body

9. Common settings for UIButton:

? -(void) Settitle: (nsstring*) title forstate: (uicontrolstate) state;

? Set the text of a button

? -(void) Settitlecolor: (Uicolor *) color forstate: (uicontrolstate) state;

? Set the text color of a button

? -(void) SetImage: (UIImage *) image forstate: (uicontrolstate) state;

? set a small picture inside the button

? -(void) SetBackgroundImage: (UIImage *) image forstate: (uicontrolstate) state;

? Set the background picture of the button

? Set the text font of the button (you need to get the label inside the button to set it)

? Btn.titleLabel.font =[uifont systemfontofsize:13];

Note : better not go through Btn.titleLabel.text to set the button text , but by Settitle: method to set the button text , because the button text has different states

? -(nsstring*) Titleforstate: (uicontrolstate) state;

? Get the text of the button

? -(uicolor*) Titlecolorforstate: (uicontrolstate) state;

? Get the text color of the button

? -(uiimage*) Imageforstate: (uicontrolstate) state;

? get the small picture inside the button

? -(uiimage*) Backgroundimageforstate: (uicontrolstate) state;

? Get the background picture of the button

9. loading process for xib files:

1. According to the path , search for the corresponding xib file (nib file )

2. When loading the xib file , each control in the xib file is loaded sequentially .

3. for each control , It is created to find the class that is configured in the corresponding class attribute. Then create an object of the corresponding class.

4. After creating a control , follow the values of the properties configured in Xib. Assign values to the properties of the object in turn.

5. Create the child controls under the control , and set the property values. The control is then added to the parent control.

6. Finally, an array is returned that contains the root element object that was created.

iOS basic Knowledge--02

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.