3

I need a example of how to use CGPoint with a if statement to check the x and y coordinates

like something like this

if(CGPoint == (XCORDINATE, YCORDINATE)){
do stuff
}

and then i need a example of how to check the x and y coordinates on a label

if(mylabel == (xpoint, ypoint)){
do stuff
}

Thanks

Jacob
  • 1,459
  • 2
  • 19
  • 32

2 Answers2

14

You get various CGPoints position for labels, using their properties. For example if you need to get the center point, get myLabel.center.

There are functions to create and compare points as described in CGGeometry Reference.

So for example you can do something like :

CGPoint testPoint = CGPointMake(50.0, 50.0);
if(CGPointEqualToPoint(testPoint, myLabel.center)) {
    // the two points equal
}
Abizern
  • 146,289
  • 39
  • 203
  • 257
  • Ahh i see, hate to burden you, but just a quick question, what if lets say im using a image, and when this label passes over this image it goes to hidden. Instead of making it have to be at exactly these points of mine, can i make it be like a box thats 50-50-50-50? so within this box with all sides that are 50 in lenght? – Jacob Jul 25 '11 at 08:41
  • so check the link I put. there are other methods to create and compare not just points but rects. your goal seems to be comparing the `frame` properties of two views (`CGRect`s). try one of the methods for checling rects equality, or maybe `CGRectContainsRect()` –  Jul 25 '11 at 08:49
  • Ahh Thanks Dude! didnt even notice the link. Appreciated – Jacob Jul 25 '11 at 08:52
  • @Jacob you are welcome, I'll make it a bit more visible for others too –  Jul 25 '11 at 08:53
1
if( point.x == XCORDINATE && point.y == YCORNDINATE )
{
   // do stuff
}

If you want to check the coördinates of a label you simply do the above, and you get the location using:

CGPoint point = yourLabel.frame.origin;
Antwan van Houdt
  • 6,989
  • 1
  • 29
  • 52