If you want to find out the top left, top right, bottom left and bottom right coordinates of your CGRect. Following is how you do it.
CGRect b=CGRectMake(40, 50, 240, 150);
//top left
float topLX=CGRectGetMinX(b);
//top right
//bottom right
NSLog(@"(%f,%f)",bottomRX,bottomRY);
CGRect b=CGRectMake(40, 50, 240, 150);
//top left
float topLX=CGRectGetMinX(b);
float topLY=CGRectGetMinY(b);
NSLog(@"(%f,%f)",topLX,topLY);
//top right
float topRX=CGRectGetMaxX(b);
float topRY=CGRectGetMinY(b);
NSLog(@"(%f,%f)",topRX,topRY);
//bottom left
float bottomLX=CGRectGetMinX(b);
float bottomLY=CGRectGetMaxY(b);
NSLog(@"(%f,%f)",bottomLX,bottomLY);
//bottom right
float bottomRX=CGRectGetMaxX(b);
float bottomRY=CGRectGetMaxY(b);
It will print following results
top left (40.000000,50.000000)
top right (280.000000,50.000000)
bottom left (40.000000,200.000000)
bottom right (280.000000,200.000000)
If this is not what you were looking for CGRect, try this comprehensive LIST.
If this is not what you were looking for CGRect, try this comprehensive LIST.
well Explained.great work.but small amendment on above code. Replace 'b.frame' to 'b' ,because b is already a rect(i guess).
ReplyDeleteOops. Thanks Chandra for pointing it out.
ReplyDelete