Search code examples
swiftuiimagecgrectcgpointcgrectmake

Split the CGPoint numbers in two CGFloat


Hey guys I have a UIImage that should move to a position which the CGPoint tells.

My code:

person1 = UIImageView(frame: CGRectMake(corX, corY, 25, 25))

What I want to do is to split the CGPoint in two numbers which initialise corX and corY. Hopefully you can help me.

-Lukas


Solution

  • CGPoint has properties x and y:

    person1 = UIImageView(frame: CGRectMake(point.x, point.y, 25, 25))
    

    Alternatively create the CGRect directly from your point as the origin and a given size:

    person1 = UIImageView(frame: CGRect(origin: point, size: CGSize(width: 25, height: 25)))