IOS review note 13: Common struct

Source: Internet
Author: User

IOS review note 13: Common struct
Both must contain the header file of Foundation. h.
CG: CoreGraphics framework for short. The content starting with CG is declared in the Foundation framework, but not implemented.
NS: NextStep


1. Range of nsange
1 Definition:

typedef struct _NSRange{NSUInteger location;NSUInteger length;}NSRange;


2 example:
NSString * str = @ "I love OC"; // nsange * rg = {2, 4}; // nsange * rg = {. location = 2 ,. length = 4}; nsange * rg = NSMakeRange (2, 4); nsange * r = [str rangOfString: @ "love"]; // "love" character, starting from 2, the length is 4 nsange p0 = nsangezero; // determines whether it is equal and returns the bool Value


Two NSPoint/CGPoint


1 Definition:
CGFloat: 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); // returns the bool value if it is equal.




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 whether the values are equal and return the bool Value



Four NSRect/CGRect rectangle
1 Definition
typedef struct _NSRect{NSPoint origin;NSSize size;}NSRect;typedef NSRect CGRect;


2 Examples
CGRect r = CGRectMake (0, 0,100, 50); NSLog (@ "% @", NSStringFromRect (r); CGRect r0 = CGRectZero; CGRectEqualToRect (r, r0 ); // determine whether the bool value is equal. Return the bool value CGRectContainsPoint (r, p). // determine whether the rectangle contains vertices and return the bool value.




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.