简体   繁体   English

如何在Xcode中更改图像的高度?

[英]How can I change the height of an image in Xcode?

I am trying to adjust the height of an image by stretching it. 我正在尝试通过拉伸来调整图像的高度。 This is what I've got so far: 到目前为止,这是我得到的:

-(IBAction)buttonTapped{
UIImage *img = [UIImage imageNamed:@"water.png"];
[water1 setImage:img];  
}
-(IBAction)button2Tapped
+ (UIImage*)imageWithImage:(UIImage*)img 
          scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext( newSize );
[img drawInRect:CGRectMake(0,2,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return newImage;}

and this is in my view controller.h 这是在我的视图controller.h中

IBOutlet UIImageView *water1;
-(IBAction)buttonTapped;
-(IBAction)button2Tapped;

I am not sure what I need to change to make this correct, or if I should start again with a new way. 我不确定需要做些什么来使此正确,或者我是否应该以一种新的方式重新开始。 I want it so that when I push a button, an image appears, then it resizes it when I push another button. 我想要它,这样当我按下一个按钮时,会出现一个图像,然后当我按下另一个按钮时,它会调整其大小。

Thanks for helping! 感谢您的帮助!

You can simply change the size of the UIImageView property, in order to get the size you want. 您可以简单地更改UIImageView属性的大小,以获得所需的大小。

Set the contentMode of the UIImageView to wathever fits your need, and it will automatically resize to the given size (either scaling to fit or stretching). 将UIImageView的contentMode设置为完全适合您的需要,它将自动调整为给定的大小(缩放以适合或拉伸)。

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

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