Swift - checking the size of UIImageView

I am trying to print a string in the debugger / console to show the dimensions of the UIImageView object I have. I tried to use the following code, but I get an error: UIImageView does not have a member named 'size'. This was my code:

    @IBOutlet var Image: UIImageView!

override func viewDidLoad() {

        super.viewDidLoad()


    var imageHeight = Image.size.height
    var imageWidth = Image.size.width

print (imageHeight)
print (imageWidth)

}

      

+3


source to share


2 answers


Before getting to your question, a few points:

Do not start an instance variable name with uppercase.



Do not use "image" for an image variable name. This suggests what it is UIImage

. This is UIImage Kind , not UIImage

. Call it something like theImageView

.

Now to your question: UIView objects do not have a size property ( UIImage

objects do have a size property. That might be the reason for your confusion.) They have a border rectangle and a border rectangle. You can use theImageView.bounds.size

or theImageView.frame.size

.

+8


source


try it



println(self.frame.height)
println(self.frame.width)

      

+1


source







All Articles