Alessandro Giovagnoli Alessandro Giovagnoli - 5 months ago 7
iOS Question

Calling an ImageView variable inside an if statement

I'm using

Swift
in
Xcode
and that's my issue:

I want to declare a variable where I want to store an
UIImageView
(Not an
UIImage
, but an
UIImageView
), so I tried something like that

var nameVariable = UIImageView()


Then I need to recall this nameVariable inside an if statement

if(\(nameVariable).center.y > something){..}


I tried using "(nameVariable)" but it doesn't work, can you help me?

Answer

Declare Variable

var img=UIImageView()

Then use it

if img.center.y > 50 {  
 //do stuff here           
}