iOS Development Learning User Interface (3) iOS coordinate system and UILabel and UIButton

Source: Internet
Author: User
Tags border color set background uicontrol

Note: The controller's view is transparent by default and needs to be set to its background.

A. Create a Uilabel object, using the initialization method with the frame parameter.

This parameter is a struct type that contains the position, dimensions, of the UI object that is displayed on the view.

IOS coordinate system:

The upper-left corner of the screen is the (0,0) starting point,

end point: (different equipment sizes vary by generation)

3GS and before: (320,480)-pixels-(320,480)

4,4s: (320, 480)-pixels-(640,960)

5,5s: (320,568)

6,6s: (375,667) (plus:414,736)

B. Add the Uilabel object to the view of the current controller.

Uilabel Basic Properties

. text//Set text

. Font//Set text font {

Size

Lb.font = [Uifont systemfontofsize:17];

Bold body

Lb.font = [Uifont boldsystemfontofsize:30];

Italic, only valid in English

Lb.font = [Uifont italicsystemfontofsize:17];

Font of the system

Nsarray *arrfonts = [Uifont familynames];

Set a custom font

Lb.font = [Uifont fontwithname:@ "Bodoni oldstyle" size:14];

}

. TextColor//Set text color {

Set Background color

Lb.backgroundcolor = [Uicolor Redcolor];

Custom color values

Lb.backgroundcolor = [Uicolor colorwithred:199.0/255.0 green:150.0/255.0 blue:100.0/255.0 alpha:1.0];

}

. TextAlignment//Set text layout

. BackgroundColor//Set text background

. Linebreakmode//Set text wrapping mode {

Lb.linebreakmode = nslinebreakbyclipping;

Lb.linebreakmode = Nslinebreakbytruncatinghead;

Lb.linebreakmode = Nslinebreakbytruncatingtail;

Lb.linebreakmode = nslinebreakbywordwrapping

}

. NumberOfLines//Set the number of lines of text, set to 0 for any number of lines, will wrap

. Clipstobounds//sets whether to cut the boundaries of sublayers or sub-views to the boundaries of the primary layer or the main view

. adjustsfontsizetofitwidth//Text size to fit the width of the View object

. minimumscalefactor//Minimum text scaling factor 0~1 range,

. Shadowcolor//The shadow color of the view

. Shadowoffset//The shadow of the view deviates from position

. Layer//Set the properties of the view object's layers {

-.bordercolor//Set the border color of the view

-.borderwidth//Set the border width of the view

-.cornerradius//Set the fillet radian of the View

}

. Attributedtext//Setting text with attributes

Gets the width, height of the current view

CGFloat w = self.view.frame.size.width;

CGFloat h = self.view.frame.size.height;

Attention:

Paste the label onto the view

[Self.view addsubview:lb];

/*

App Development:

Native (page on client)

Web page (page on server side)

Mixed (First mix)

Site recommendation: coredova--Development mixed frame, Apicloud

*/

To create a variable property with attribute text

nsmutableattributedstring *attrstr = [[Nsmutableattributedstring alloc] initWithString:lb.text];

Add attributes to Text

[Attrstr addattribute:nsfontattributename Value:[uifont Systemfontofsize:12] Range:nsmakerange (0, 2)];

[Attrstr addattribute:nsfontattributename value:[uifont systemfontofsize:12 weight:200] Range:NSMakeRange (6, 8)];

//

[Attrstr addattribute:nsforegroundcolorattributename Value:[uicolor Greencolor] Range:nsmakerange (2, 5)];

[Attrstr addattribute:nsbackgroundcolorattributename Value:[uicolor Bluecolor] Range:nsmakerange (2, 5)];

//

Lb.attributedtext = Attrstr;

Study

Core text text layout

UIButton

button that the user can touch and give the user a response to the view control.

Inherit from Uicontrol (Uicontrol inherit from UIView), note the difference from Uilabel

Uicontrol? is the base class for all control class objects (such as buttons, sliders, and so on).

Control? iOS programming is event-driven. An event is an object that is sent to an application to notify the user of its action. After an event occurs, a message is sent to the application (the UIApplication object), which distributes the message, specifying who will handle the event.

UIButton creation and basic properties, methods

Two kinds of initialization methods:

initWithFrame:

Buttonwithtype: Creates a button with a system-given type, noting that some types are invalid.

. Layer//Layers property Set button border

Settitle:forstate://Set text in different button states {

Sets the text of the button with an enumeration that moves left or right to make or, to, or operate

[Btn settitle:@ "I am a" forstate:uicontrolstatenormal];

UIControlStateNormal = 0,//normal state

uicontrolstatehighlighted = 1 << 0,//Highlight status//used when Uicontrol ishighlighted is set

uicontrolstatedisabled = 1 << 1,//disabled status

uicontrolstateselected = 1 << 2,//Selected status//flag usable by app (see below)

Uicontrolstateapplication = 0x00ff0000,//additional flags available for application use

uicontrolstatereserved = 0xff000000

}

. Titlelabel//button on the Uilabel of the text, read-only property {

Access the Label,redonly in the button

Btn.titleLabel.text = @ "I have been modified";

Btn.titleLabel.backgroundColor = [Uicolor Redcolor];

}

Settitlecolor:forstate://Set text color in different button states

Setcontenthorizontalalignment://Setting the horizontal layout of the button contents

{

Set the layout of button content

[Btn Setcontenthorizontalalignment:uicontrolcontenthorizontalalignmentright];

[Btn Setcontentverticalalignment:uicontrolcontentverticalalignmentbottom];

}

Setcontentverticalalignment://Set the vertical layout of the button contents

. backgroundcolor//button background color, not associated with state

SetSelected://Make button selected {

Make the button selected

[Btn Setselected:yes];

}

Setbackgroundimage:forstate://Set background picture in different button states [background color changes with state? ]

Setimage:forstate://Set foreground picture in different button states {

Add foreground picture

[Btn setimage:[uiimage imagenamed:@ "Btntree"] forstate:uicontrolstatenormal];

}

{

UIImage? Picture data. Three methods of initialization:

Imagenamed://Read the picture from the cache, if none, then find it from the package, then cache it and return it. Otherwise, nil is returned.

Imagewithcontentsoffile://Find a picture directly from the path

Imagewithdata://Create a picture from binary data

* Get picture size from UIImage

Binary stream

NSData *dataforimg = [NSData datawithcontentsoffile:@ "/users/arlen/desktop/code/uibuttonbasic/uibuttonbasic/ Btnbackchange.png "];

UIImage *imgforuse2 = [UIImage imagewithdata:dataforimg];

}

UIButton Status, Event

State//can set the status of the button, Normal, highlight, select and so on. The button initially is in a normal state, and when clicked, the status changes.

AddTarget:action:forControlEvents://Add target objects and behaviors for a particular event. (actually registering the add operation in the internal message sub-publication)

/* Target: Destination object, recipient of message

Action: The selector that identifies the behavior

ControlEvents: Event Type

*/

iOS Development Learning User Interface (3) iOS coordinate system and UILabel and UIButton

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.