iOS Development Basics-Fragmentation 3

Source: Internet
Author: User

12: Judging the equipment

//Device Namereturn[Uidevice currentdevice].name;//device model, only can get what equipment, cannot get is the first generation of equipmentreturn[Uidevice Currentdevice].model;//system version models, such as iphone OSreturn[Uidevice currentdevice].systemversion;//system version name, such as 6.1.3return[Uidevice currentdevice].systemname;//determine if the iphone#defineIs_iphone (ui_user_interface_idiom () = = Uiuserinterfaceidiomphone)//determine if the ipad#defineIs_ipad (ui_user_interface_idiom () = = Uiuserinterfaceidiompad)//determine if the ipod#defineIs_ipod ([[[[Uidevice Currentdevice] model] isequaltostring:@ "IPOD Touch"])//determine if it is iPhone5#defineIs_iphone_5_screen [[UIScreen mainscreen] bounds].size.height >= 568.0f && [[UIScreen mainscreen] bounds]. Size.Height < 1024.0f

13: Use of enumerations

typedefenum  {      //The following is an enumeration memberTestA =0, Testb, TESTC, TestD} Test;//Enumeration Namecan also be defined as follows (recommended: the structure is clearer), where Test1 is the name of the enumeration: TypeDef ns_enum (Nsinteger, Test1) {//The following is an enumeration memberTEST1A =0, test1b=1, test1c=2, TEST1D=3  }; The definition of the enumeration also supports the way in which bit operations are defined, moving to the left several, which is binary (the equals sign must be equal to 1), to decimal, as follows: TypeDef ns_enum (Nsinteger, Test) {TestA=1,//1 1 1TESTB =1<<1,//2 2 10 convert to 10 binary 2TESTC =1<<2,//4 3 100 convert to 10 binary 4TestD =1<<3,//8 4 1000 convert to 10 Binary 8Teste =1<<4  //16 5 10000 converted 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 typedeffloatCGFloat;//32-bittypedefDoubleCGFloat;//64-bitstructCgpoint {cgfloat x; CGFloat y;}; typedefstructCgpoint Cgpoint;structcgsize {cgfloat width; CGFloat height;}; typedefstructcgsize cgsize;structCGRect {Cgpoint origin; Cgsize size;}; typedefstructCGRect 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) //  {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); } 

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.