Answer the question
In order to leave comments, you need to log in
Swift - how to move and resize UIImageView programmatically?
In the View Controller Scene, I have created a UIView on which lies a UIImageView containing an image.
Depending on the screen size of the device, on startup, this ImageView should resize.
(to be precise, it should be square, with a side equal to the width of the screen)
I created a child class MyImageView in which I changed the constructor, adding code that should change the size and position of the object, but it does not change anything at all.
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
var screenWidth = UIScreen.mainScreen().bounds.width
self.bounds = CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: screenWidth, height: screenWidth))
self.frame = CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: screenWidth, height: screenWidth))
}
Answer the question
In order to leave comments, you need to log in
In the View Controller Scene, I add an Image View and in the Identity Inspector, in the Custom Class section, I indicate that this is an object of the MyImageView class.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question