iOS Development Basics-Fragmentation 3

Source: Internet
Author: User

12: Judging the equipment

Device name return [Uidevice currentdevice].name; Equipment model, only can get what equipment, can not get is the first generation of equipment return [Uidevice Currentdevice].model; System version model, such as iphone OS return [Uidevice currentdevice].systemversion; The system version name, such as 6.1.3return [Uidevice currentdevice].systemname;//, determines whether it is Iphone#define Is_iphone (Ui_user_interface_idiom ( ) = = Uiuserinterfaceidiomphone)//Determine if Ipad#define Is_ipad (ui_user_interface_idiom () = = Uiuserinterfaceidiompad)// Determine if Ipod#define is_ipod ([[[[[[[Uidevice Currentdevice] model] isequaltostring:@ "IPOD touch")//Determine if Iphone5#define is_ Iphone_5_screen [[UIScreen mainscreen] bounds].size.height >= 568.0f && [[UIScreen mainscreen] bounds]. Size.Height < 1024.0f

13: Use of enumerations

typedef enum  {      //The following is an enumeration member      TestA = 0,      testb,      testc,      TestD  }test;//Enumeration name can also be defined as follows (recommended: The structure is relatively clear ), where Test1 is the name of the enumeration: TypeDef ns_enum (Nsinteger, Test1)  {      ///The following is an enumeration member      TEST1A = 0,      test1b = 1,      test1c = 2,      test1d = 3  }; The definition of the enumeration also supports the way the bitwise operation is defined, moving to the left several, it is binary (equals sign must be equal to 1), to decimal, as follows: TypeDef ns_enum (Nsinteger, Test)  {      TestA       = 1,      //1   1   1      testb       = 1 << 1,//2   2      converted to 10 binary  2      TESTC       = 1 << 2,//4   3     convert to 10 binary  4      TestD       = 1 << 3,//8   4   Convert to    10 binary  8      teste       = 1 << 4  //16  5   10000 convert to   10 binary  }; You can call operations on the above: Test Tes=testb;    NSLog ("%ld", TES);--->2test newtes= (testa| TESTC);   NSLog ("%ld", newtes);--->5

14: CGFloat, Cgpoint, Cgsize, and CGRect in iOS development

1. Data type:

CGFloat: Basic type of floating-point value cgpoint: Represents a point cgsize in a two-dimensional coordinate system: represents the width and height of a rectangle CGRect: represents the position and size of a rectangle typedef float cgfloat;//32-bittypedef Double cgfloat;//64-bitstruct cgpoint {    cgfloat x;    CGFloat y;}; typedef struct CGPOINT cgpoint;struct cgsize {    cgfloat width;    CGFloat height;}; typedef struct CGSIZE cgsize;struct CGRect {    cgpoint origin;    Cgsize size;}; typedef struct CGRECT CGRect;

Note: The height and width of the CGRect data structure can be negative. For example, the origin of a rectangle is [0.0,0.0] and the size is [10.0,10.0]. The rectangle that is exactly the same as the origin is [10.0,10.0] and the size is [ -10.0,-10.0] of the rectangle.

2. Methods for creating geometric elements using values

Cgpointmakecgrectmakecgsizemakecgpoint Cgpointmake (   cgfloat x,   cgfloat y); Cgsize Cgsizemake (   cgfloat width,   cgfloat height); CGRect CGRectMake (   cgfloat x,   cgfloat y,   cgfloat width,   cgfloat height); CGFloat ten=10.0f; Cgpoint point = Cgpointmake (0.0f, 0.0f); Cgsize size = Cgsizemake (10.0f, 10.0f); CGRect rect = CGRectMake (Point.x, Point.y, Size.width, size.height); NSLog (@ "Ten:%f", ten); NSLog (@ "point:%@", Nsstringfromcgpoint (point)); NSLog (@ "Size:%@", nsstringfromcgsize (size)); NSLog (@ "rect:%@", Nsstringfromcgrect (rect));

XV: iOS dynamically gets the height and width of the Uilabel

When you use Uilabel to store strings, you often need to get the long-width data for the label, which is a list of some common computational methods.

1. Get the width to get the length of the string without wrapping the row line

Cgsize titlesize = [astring sizewithfont:font constrainedtosize:cgsizemake (Maxfloat, 30)];

Note: The width of size should be set to maxfloat if it is desired.

2. Gets the height that gets the actual height required for the string to wrap within the specified size (the width of the label is more than the line).

Cgsize titlesize = [astring sizewithfont:font constrainedtosize:cgsizemake (label.frame.size.width, Maxfloat) Linebreakmode:uilinebreakmodewordwrap];

Note: The height of size should be set to maxfloat if you want to get high.

3. When actually programming, sometimes you need to calculate the position of the last character of a piece of text, and then add a picture or other control (such as the info icon), the following code is the method to calculate the position of the last character in the label.

Cgsize sz = [Label.text sizeWithFont:label.font constrainedtosize:cgsizemake (Maxfloat, 40)]; Cgsize linessz = [Label.text sizeWithFont:label.font constrainedtosize:cgsizemake (label.frame.size.width, Maxfloat) Linebreakmode:uilinebreakmodewordwrap];if (sz.width <= linessz.width)//Determine if the line is folded {   lastpoint = CGPointMake ( Label.frame.origin.x + sz.width, LABEL.FRAME.ORIGIN.Y);  } else  {     lastpoint = Cgpointmake (label.frame.origin.x + (int) sz.width% (int) Linessz.width,linessz.height- Sz.height);  

16: Use of a string with attributes (nsmutableattributedstring)

1. Create object NSString *original = @ "Are you all right today?"  "; nsmutableattributedstring *attrtitle = [[Nsmutableattributedstringalloc] initwithstring:original];2. Set the Color (      Nsforegroundcolorattributename to set the color, value for value, range for scope)/** Other settings: 1.NSForegroundColorAttributeName//color 2.NSFontAttributeName//font 3.NSBackgroundColorAttributeName//Background color//There are many other properties that you can go to see the Apple API, no longer detailed here */[Attrtit Le addattribute:nsforegroundcolorattributename value:[uicolorbluecolor] range:nsmakerange (0, 2)];3. Add to label    UILabel *label = [[UILabel alloc] init];    Label.frame = CGRectMake (+, +, +);    [Label Setattributedtext:attrtitle];    [Self.view Addsubview:label];

iOS Development Basics-Fragmentation 3

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.