简体   繁体   English

如何调整UIImageView的大小?

[英]How to resize UIImageView?

I've a UIImageView called img . 我有一个名为imgUIImageView

How do I change it's size, let's say, increase it by 1.0 each time a press a button ? 假设每次按下按钮时,如何将其大小增加1.0

It sounds like what you need is to adjust this size of UIImageView , not really change size of UIImage . 听起来您需要调整UIImageView size ,而不是真正更改UIImage大小。 You can assign a new frame value of this UIImageView. 您可以为此UIImageView分配新的框架值。

CGRect newFrame = img.frame;
newFrame .size.width += 1;
newFrame .size.height += 1;
img.frame = newFrame ;

Simply by setting a different frame (and an appropriate content mode). 只需设置其他框架(以及适当的内容模式)即可。 For example: 例如:

- (IBAction) buttonWasPressed
{
    [imageView setFrame:CGRectInset([imageView frame], -20, -20)];
}

Note that this only changes the view size, not the underlying image data. 请注意,这仅更改视图大小,而不更改基础图像数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM