views:

23

answers:

1

Hi
How do you obtain the x,y coordinates of a custom UIVIew?

NSLog(@"landscape orientation and myUIView.x==%f and myUIView.y==%f",myUIView.position.x ,myUIView.position.y )

I get the following error

request for member 'position' in something not a structure or union
+2  A: 

UIView does not have a position property but it does have a frame property (documented here) which is a CGRect. CGRect contains the origin (x/y coordinates) and size.

NSLog(@"landscape orientation and myUIView.x==%f and myUIView.y==%f",
    myUIView.frame.origin.x,
    myUIView.frame.origin.y )

The frame's coordinates are in the coordinate system of the parent UIView (superview).

EDIT I recently learned another way to print coordinates:

NSLog(@"myUIView origin=%@", NSStringFromCGPoint(myUIView.frame.origin));

or the entire CGRect:

NSLog(@"myUIView frame=%@", NSStringFromCGRect(myUIView.frame));
progrmr