Question

How do we get all four coordinates of a UIView? I thought this would be it.

CGPoint viewOriginX = [self.view convertPoint:self.view.frame.origin fromView:nil];

But what about CGPoint of the top right, bottom left and bottom right points?

Was it helpful?

Solution

CGRect frame = [self.view frame];
CGPoint topLeft = CGPointMake(CGRectGetMinX(frame), CGRectGetMinY(frame));
CGPoint topRight = CGPointMake(CGRectGetMaxX(frame), CGRectGetMinY(frame));
CGPoint bottomLeft = CGPointMake(CGRectGetMinX(frame), CGRectGetMaxY(frame));
CGPoint bottomRight = CGPointMake(CGRectGetMaxX(frame), CGRectGetMaxY(frame));

If you need those coordinates in a particular view, the first line should be something like

CGRect frame = [self.view convertRect:[self.view bounds] toView:someOtherView];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top