Black Horse programmer ___ Foundation _ struct

Source: Internet
Author: User

Struct

 

Nsange:

 

Used to indicate the range

 

Create

Nsange R1 = {2, 4}

Nsange r2 = {. Location = 2,. Length = 4}

Nsange R3 = nsmakerange (2, 4)

 

Search for the range of a string in Str

Nsstring * STR = @ "I love OC ";

Nsange range = [STR rangeofstring: @ "Java"]

Nslog (@ "location = % lD, length = % lD", range. Location, range. length)

 

If not found, length = 0, location = nsnotfound =-1

 

 

Nspoint:

 

Used to represent the coordinates of a point

 

Create

 

Cgpoint p1 = nsmakepoint (10, 10 );

Nspoint P2 = cgpointmake (20, 20 );

Indicates the origin

Cgpointzero = cgpointmake (0, 0)

 

Nssize:

 

Indicates the size of a two-dimensional plane.

 

Nssize S1 = cgsizemake (100, 50 );

Nssize S2 = nsmakesize (100, 50 );

Cgsize S3 = nsmakesize (200, 60 );

 

Cgrect:

 

Represents a specific dimension and position of a two-dimensional plane.

 

Cgrectr1 = cgrectmake (0, 0,100, 50 );

Cgrect r2 = {0, 0 },{ 100, 90 }};

Cgrect R3 = {p1, S2 };

 

Another method for defining cgrect

 

 

Cgrect myrect (cgfloat X, cgfloat y, cgfloat width, cgfloat height)

{

Cgrect rect;

Rect. Origin. x = X;

Rect. Origin. Y = y;

Rect. Size. width = width;

Rect. Size. Height = height;

}

 

Convert struct to string

Nsstring * STR = nsstringfrompoint (P1 );

Nsstring * STR = nsstringfromsize (S3 );

Nsstring * STR = nsstringfromrect (R1 );

Compare whether the two points are the same (x, y)

Bool B = cgpointequaltopoint (cgpointmake (10, 10), cgpointmake (10, 10 ))

Determines whether a point is in a region.

Bool b2 = cgrectcontainspoint (cgrectmake (50, 40,100, 50), cgpointmake (60, 45 ))

 

The premise of using these cgpointequaltopoint, cgrectcontainspoint, and other functions is to add the CoreGraphics framework.

 

Black Horse programmer ___ Foundation _ struct

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.