【发布时间】:2017-01-31 08:21:44
【问题描述】:
我正在使用 Swift 3 并尝试更改我在 xib 中的 UIImageView 宽度和高度
这是我的代码:
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
当我尝试像这样更改图像视图框架时
imageView.frame = CGRect(x: imageView.frame.origin.x, y: imageView.frame.origin.y - 40, width: 200, height: imageView.frame.height)
当我尝试运行它时没有任何变化,请帮我解决这个问题
【问题讨论】:
-
你有没有在这一行得到正确的图像视图:让 imageView = view.viewWithTag(1) as! UIImageView
-
var frame = self. imageView.frame frame.size.width = 100;框架.尺寸.高度 = 100;自己。 imageView.frame = 框架自身。 imageView .setNeedsDisplay()
-
@KKRocks 我已经设置好了,我可以更改imageview的图像没有任何问题,只是不能更改宽度和高度
-
@karthikeyan 代码不行,已经试了好几次了
-
第一件事。你一开始能正确显示 imageView 吗?其次,尝试使用 imageView 的边界而不是它的框架,因为它们不使用相同的坐标空间。 imageView.frame = CGRect(x: imageView.bounds.origin.x, y: imageView.bounds.origin.y - 40, width: 200, height: imageView.bounds.height)
标签: ios swift uiview uiimageview swift3