cgrectmake
iOS frame change one property (eg width)
To answer your original question: yes, it’s possible to change just one member of a CGRect structure. This code throws no errors: myRect.size.width = 50; What is not possible, however, is to change a single member of a CGRect that is itself a property of another object. In that very common case, you would have … Read more
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)
Update CGRectMake to CGRect in Swift 3 Automatically
The simplest solution is probably just to redefine the functions Apple took away. Example: func CGRectMake(_ x: CGFloat, _ y: CGFloat, _ width: CGFloat, _ height: CGFloat) -> CGRect { return CGRect(x: x, y: y, width: width, height: height) } Put that in your module and all calls to CGRectMake will work again.
How to initialize properties that depend on each other
@MartinR has pointed out the major issue here: var corX = 0 var corY = 0 var panzer = UIImageView(frame: CGRectMake(corX, corY, 30, 40)) The problem is that a Swift default initializer cannot refer to the value of another property, because at the time of initialization, the property doesn’t exist yet (because the instance itself … Read more