I am trying to print a line to the debugger/console to show the dimensions of the UIImageView object I have. I was trying to use the following code but get an error saying UIImageView doesn't 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)
}
Before we get to your question, several points:
Don't start the name of an instance variable with upper case.
Don't use "image" for the variable name of an image view. That suggests that it is a UIImage
. It's a UIImageView, not a 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 cause of your confusion.) They have a bounds rectangle and a frame rectangle. You can use theImageView.bounds.size
or theImageView.frame.size
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With