How do I create a CGRect from a CGPoint and CGSize?

inorganik picture inorganik · Aug 21, 2012 · Viewed 65.3k times · Source

I need to create a frame for a UIImageView from a varying collection of CGSize and CGPoint, both values will always be different depending on user's choices. So how can I make a CGRect form a CGPoint and a CGSize? Thank you in advance.

Answer

Jim picture Jim · Aug 21, 2012

Two different options for Objective-C:

CGRect aRect = CGRectMake(aPoint.x, aPoint.y, aSize.width, aSize.height);

CGRect aRect = { aPoint, aSize };

Swift 3:

let aRect = CGRect(origin: aPoint, size: aSize)