iOS Review note 13: Common structures

Source: Internet
Author: User

Need to include Foundation.h header files
Cg:coregraphics framework abbreviation, CG at the beginning of the framework of the foundation is declared, but not implemented
Ns:nextstep


One Nsrange Range
1 Definition:
typedef struct _NSRANGE{NSUINTEGER location; Nsuinteger length;} Nsrange;


2 Example:
nsstring* str = @ "I love OC";//nsrange* RG = {2, 4};//nsrange* RG = {. Location = 2,. length = 4}; nsrange* RG = Nsmakerange (2, 4); nsrange* r = [str rangofstring:@ ' love '];//' love ' character, starting from 2, length 4NSRange P0 = nsrangezero;//determine equality, return bool value


Two nspoint/cgpoint points


1 Definition:
CGFloat is doubletypedef _nspoint{cgfloat x; CGFloat y;} Nspoint;typedef Nspoint Cgpoint;

Cgpoint Cross-platform


2 Example:
Cgpoint p = cgmakepoint (10, 10); Cgpoint p = cgpointmake (10, 10); NSLog (@ "%@", Nsstringfrompoint (p)); Cgpoint p0 = Cgpointzero; Cgpointequaltopoint (P, p0);//Determine equality, return bool value




Three Nssize/cgsize
1 Definition:
typedef struct _NSSIZE{CGFLOAT x; CGFloat y;} Nssize;typedef nssize cgsize;

2 Example:
Cgsize sz = Cgsizemake (10, 10); NSLog (@ "%@", Nsstringfromsize (SZ)); Cgsize sz0 = Cgsizezero; Cgsizeequaltosize (SZ, sz0);//Determine equality, return bool value



Four Nsrect/cgrect Rectangle
1 definitions
typedef struct _NSRECT{NSPOINT origin; Nssize size;} Nsrect;typedef Nsrect CGRect;


2 Example
CGRect r = CGRectMake (0, 0, 100, 50); NSLog (@ "%@", Nsstringfromrect (R)); CGRect r0 = Cgrectzero; Cgrectequaltorect (R, R0);//Determine equality, return bool value Cgrectcontainspoint (r, p);//Determine if the rectangle contains a point, return a bool value




iOS Review note 13: Common structures

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.