The structures that are frequently used in objective-C include nsange, nspoint, nssize (cgsize), and nsrect.

Source: Internet
Author: User

The structures that are frequently used in objective-C include nsange, nspoint, nssize (cgsize), and nsrect.


1 nsange

The prototype of nsange is

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

Nsmakerange Functions

Ns_inlinez is the inline function typedef nsange * nsangepointer; ns_inline nsange nsmakerange (nsuinteger Loc, nsuinteger Len) {nsange R; R. Location = LOC; R. Length = Len; return r ;}


Usage

// The Value of "nsange range" indicates the range of "nsange range" and "range. location = 18; range. length = 34; nslog (@ "location is % zi", range. location); nslog (@ "length is % zi", range. length); // create range = nsmakerange (8, 10); nslog (@ "location is % zi", range. location); nslog (@ "length is % zi", range. length); // nsstringfromrange converts the above struct to the string type and prints the nsstring * str1 = nsstringfromrange (range); // % @ is an OC object, range represents a struct, and STR is an OC object nslog (@ "Rang is % @", str1 );

2 nspoint

Nspoint prototype

struct CGPoint {     CGFloat x;     CGFloat y;     };

Nsmakepoint Function

NS_INLINE NSPoint NSMakePoint(CGFloat x, CGFloat y) {     NSPoint p;     p.x = x;     p.y = y;     return p;     }

Cgpointmake Function

CGPointMake(CGFloat x, CGFloat y)     {     CGPoint p; p.x = x; p.y = y; return p;     }

Usage

// Nspoint indicates the position nspoint point; // assign a value to the point in the struct. X = 10; point. y = 10; // high-speed creation point = nsmakepoint (10, 18); // a common function is cgpointmake's Function Point = cgpointmake (29, 78 ); nsstring * str2 = nsstringfrompoint (point); nslog (@ "point is % @", str2 );

3 cgsize

Cgsize prototype

struct CGSize {     CGFloat width;     CGFloat height;     };

Nsmakesize Function

NS_INLINE NSSize NSMakeSize(CGFloat w, CGFloat h) {     NSSize s;     s.width = w;     s.height = h;     return s;     }

Cgsizemake Function


CGSizeMake(CGFloat width, CGFloat height)     {     CGSize size; size.width = width; size.height = height; return size;     }

Usage

 NSSize size;       size.width = 100;    size.height = 12;    size = NSMakeSize(12, 12);    size = CGSizeMake(11, 11);        NSString* str3 = NSStringFromSize(size);    NSLog(@"%@",str3);

4 cgrect

Cgrect prototype

struct CGRect {     CGPoint origin;     CGSize size;     };

Cgrectmake Function

CGRectMake(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;     return rect;     }

Nsmakerect Function

NS_INLINE NSRect NSMakeRect(CGFloat x, CGFloat y, CGFloat w, CGFloat h) {     NSRect r;     r.origin.x = x;     r.origin.y = y;     r.size.width = w;     r.size.height = h;     return r;     }

Usage

// It includes both the size and position of nsrect rect and rect. origin. X = 12; rect. origin. y = 14; rect. size. width = 12; rect. size. height = 15; // high-speed creation method rect = cgrectmake (12, 12, 12, 12); rect = nsmakerect (11, 11, 11, 11 ); // print nsstring * str5 = nsstringfromrect (rect); nslog (@ "rect is % @", str5 );









The structures that are frequently used in objective-C include nsange, nspoint, nssize (cgsize), and nsrect.

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.