So we have a point P(200,60) inside the rect and another point O(200,400) outside the rectangle. Now we want to find it out using iPhone code. Following is how we do it
CGRect b=CGRectMake(40, 50, 280, 200);
CGPoint p=CGPointMake(200, 60);
CGPoint o=CGPointMake(200, 400);
BOOL contains=CGRectContainsPoint(b, p);
BOOL contains1=CGRectContainsPoint(b, o);
if(contains) NSLog(@"yes"); else NSLog(@"no");
//This will print yes because p is inside rect b
if(contains1) NSLog(@"yes");else NSLog(@"no");
//This will print no because o is inside rect bIf this is not what you were looking for CGRect, try this comprehensive LIST.
No comments:
Post a Comment