i_raqz
i_raqz

Reputation: 2959

CGPoints of a UIView

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?

Upvotes: 1

Views: 3284

Answers (1)

Noah Witherspoon
Noah Witherspoon

Reputation: 57149

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];

Upvotes: 9

Related Questions