iOS development OC (16)--foundation (1) struct

Source: Internet
Author: User

(a) to master the use of these

Nsrange (location length)---scope range: Range

Nspoint\ ( equivalent) cgpoint---point

Nssize\cgsize---Size

Nsrect\cgrect (cgpint cgsize)---equivalent to a rectangle

In fact, to look at official documents more clearly, these uses, need to declare the method of jump to see, here, just list simple usage, as understanding

(ii) code example

1.

voidRange () {//@ "I love OC"//the scope of love//Nsrange r1 = {2, 4}; //Don't//Nsrange r2 = {. Location = 2,. length = 4}; //Don't//Nsrange r3 = Nsmakerange (2, 4); //need to master, we generally use this, above the two readability of the poorNSString *str =@"I love OC"; //find the range of a string in str//If you can't find it, Length=0,location=nsnotfound==-1Nsrange range = [str rangeofstring:@"Java"]; NSLog (@"loc =%ld, length=%ld", Range.location, range.length);}

2.

voidPSR () {cgpoint P1= Nsmakepoint (Ten,Ten); Nspoint P2= Cgpointmake ( -, -);//most commonly usednssize S1= Cgsizemake ( -, -); Nssize S2= Nsmakesize ( -, -); Cgsize S3= Nsmakesize ( $, -); CGRect R1= CGRectMake (0,0, -, -);//most commonly used (below two as an understanding)cgrect R2= { {0,0}, { -, -}}; CGRect R3={p1, s2}; //the premise of using Cgpointzero is to add the Coregraphics framework CGRect R4 = {Cgpointzero, cgsizemake ( -, -)}; //Cgsizezero//Cgrectzero//indicates the origin.//Cgpointzero = = Cgpointmake (0, 0)//Convert struct to string//nsstring *str = Nsstringfrompoint (p1); //nsstring *str = nsstringfromsize (S3);NSString*str =Nsstringfromrect (R1); NSLog (@"%@", str); //It's a lot of trouble to print. So, we'll---to convert the struct to a string//NSLog (@ "x=%f, y=%f, width=%f, height=%f", r1.origin.x, R1.ORIGIN.Y, R1.size.width, r1.size.height);}//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;//    //return rect;//}

3. Understand

#import<Foundation/Foundation.h>intMain () {/*Nsrange (location length) nspoint\ (equivalent) cgpoint nssize\cgsize nsrect\cgrect (cgpint cgsize)*/        //The premise of using these functions, such as Cgpointequaltopoint, Cgrectcontainspoint, is to add the Coregraphics framework//NextStep Foundation//compares two points for the same (x, y)BOOL B = Cgpointequaltopoint (Cgpointmake (Ten,Ten), Cgpointmake (Ten,Ten)); //Cgrectequaltorect (< #CGRect Rect1#>, < #CGRect rect2#>)//Cgsizeequaltosize (< #CGSize Size1#>, < #CGSize size2#>)//x (in) y ( .)BOOL b2 = Cgrectcontainspoint (CGRectMake ( -, +, -, -), Cgpointmake ( -, $)); NSLog (@"%d", B2); return 0;}

iOS development OC (16)--foundation (1) 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.