The structure nsrange,nspoint,nssize (cgsize) commonly used in objective-c, Nsrect

Source: Internet
Author: User

1 Nsrange

typedef struct _NSRANGE {
Nsuinteger location;
Nsuinteger length;
} Nsrange;
Functions of the Nsmakerange

Ns_inlinez is an inline function

typedef nsrange *nsrangepointer;

Ns_inline nsrange nsmakerange (Nsuinteger Loc, Nsuinteger len) {
Nsrange R;
r.location = loc;
R.length = Len;
return R;
}
How to use

Nsrange represents a range.
Nsrange range;
Range.location = 18;
Range.length = 34;

NSLog (@ "Location is%zi", range.location);
NSLog (@ "Length is%zi", range.length);

Quickly create
Range = Nsmakerange (8, 10);
NSLog (@ "Location is%zi", range.location);
NSLog (@ "Length is%zi", range.length);

Nsstringfromrange the above structure into a string type, print out

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's 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;
}
How to use

Nspoint refers to the position
Nspoint Point;

Assigning values to points inside a struct
Point.x = 10;
Point.y = 10;

Quick Create point
Point = Nsmakepoint (10, 18);

A common function for creating points is Cgpointmake
Point = Cgpointmake (29, 78);
nsstring* str2 = Nsstringfrompoint (point);
NSLog (@ "point is%@", str2);
3 cgsize

Cgsize's 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;
}
How to use

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's prototype

struct CGRect {
Cgpoint origin;
Cgsize size;
};
Functions of the CGRectMake

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;
}
How to use

Includes both size and position
Nsrect rect;
rect.origin.x = 12;
RECT.ORIGIN.Y = 14;
Rect.size.width = 12;
Rect.size.height = 15;

Quick Create method
Rect = CGRectMake (12, 12, 12, 12);
Rect = Nsmakerect (11, 11, 11, 11);

Convert to a string to print out
nsstring* STR5 = nsstringfromrect (rect);
NSLog (@ "rect is%@", STR5);

The structure nsrange,nspoint,nssize (cgsize) commonly used in objective-c, 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.