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

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


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)


Building on the most excellent answer from @Jim, one can also construct a CGPoint and a CGSize using this method. So these are also valid ways to make a CGRect:

CGRect aRect = { {aPoint.x, aPoint.y}, aSize };CGrect aRect = { aPoint, {aSize.width, aSize.height} };CGRect aRect = { {aPoint.x, aPoint.y}, {aSize.width, aSize.height} };


CGRectMake(yourPoint.x, yourPoint.y, yourSize.width, yourSize.height);