2015-11-03 69 views
1

我如何设置UIImageView的高度并保留其他属性,因为它来自.xib?我在.xib文件中有UIImageView,但我只想以编程方式设置它的高度。可以做到吗?仅更改UIImageView的高度

回答

1

是可以做到的。例如:如果您有UIImageView作为imageView然后执行下面更改特定帧值。

路 - 1

CGRect rect = imageView.frame; 
rect.size.height = /* YOUR_HEIGHT */; 
imageView.frame = rect; 

路 - 2

imageView.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y, imageView.frame.size.width, /* YOUR_HEIGHT */); 
+0

代码工作,但似乎有一些其他的问题,ImageView的已在的.xib身高1的约束,我想0.5的高度,但它没有发生。 –