I'm using Swift 3 and trying to change my UIImageView width and height that inside xib
This is my code:
let view = Bundle.main.loadNibNamed("Custom", owner: self, options: nil)?[0] as! UIView
view.frame = CGRect(x: CGFloat(i) * self.sView.frame.size.width, y: self.sView.frame.origin.y, width: self.sView.frame.size.width, height: self.sView.frame.size.height)
let imageView = view.viewWithTag(1) as! UIImageView
when I try to change the imageview frame like this
imageView.frame = CGRect(x: imageView.frame.origin.x, y: imageView.frame.origin.y - 40, width: 200, height: imageView.frame.height)
nothing change when I try to run it, please help me how to fix this problem
I end up set identifier for my constraint in my xib and call it from my controller like this
for subview in view.subviews {
for constraint in subview.constraints as [NSLayoutConstraint] {
if constraint.identifier == "imageWidth" {
constraint.constant = view.frame.width * 0.5
}
}
}
and I can control the width, the height, the x and y from my controller
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.