Ios 仅更改UIImageView的高度

Ios 仅更改UIImageView的高度,ios,objective-c,uiimageview,Ios,Objective C,Uiimageview,如何设置UIImageView的高度,并保留.xib中的其他属性?我在.xib文件中有UIImageView,但我只想以编程方式设置它的高度。可以吗?可以。例如:如果您有UIImageView作为imageView,请执行以下操作以更改特定的帧值 方式-1 CGRect rect = imageView.frame; rect.size.height = /* YOUR_HEIGHT */; imageView.frame = rect; 方式-2 imageView.frame = CGRe

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

可以。例如:如果您有
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 */);

我强烈建议您添加到您的项目中。它允许直接使用框架,例如:

view.x = 15.;
view.width = 167.;

代码正在运行,但似乎还有其他问题,imageView在.xib中有高度1的约束,我希望高度为0.5,但它没有发生。