简体   繁体   English

如何在“.m”中调整 UIImageView 的大小

[英]How do I resize a UIImageView in the '.m'

I have a UIImageView that I want to resize when you press a button.我有一个 UIImageView,当你按下按钮时我想调整它的大小。 I haven't been able to find any on other forums or sources.我无法在其他论坛或资源中找到任何内容。

Any help appreciated,任何帮助表示赞赏,

user826671用户826671

I have made a sample using slider control.我使用 slider 控件制作了一个示例。 You can activate this slider on your button press and use it to increase or decrease the size of the images https://github.com/manishnath/Code/tree/master/zommin您可以在按下按钮时激活此 slider 并使用它来增加或减小图像的大小https://github.com/manishnath/Code/tree/master/zommin

-(void) onButtonClick { CGRect frameRect = temp.frame; -(void) onButtonClick { CGRect frameRect = temp.frame; //temp ur UIMAGEVIEW //温度你的UIMAGEVIEW

 frameRect.size.width= your_width;

 frameRect.size.height= height;

 temp.frame=frameRect;

} }

If its about UIImage, you can do it by this way.如果它是关于 UIImage 的,你可以这样做。 For UIImageView you can change its frame size.对于 UIImageView 您可以更改其帧大小。

- (UIImage *) resizeImage:(UIImage *)image newWidth:(CGFloat)width 
              newHeight: (CGFloat)height 
{
    CGRect area = CGRectMake(0, 0, width,height);
    CGSize size = area.size;

    UIGraphicsBeginImageContext(size);  
    [image drawInRect:area];    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return newImage;    
}

If you want to resize the image view itself, do like如果您想调整图像视图本身的大小,请喜欢

CGRect newRect = imageView.frame;
newRect.size.width = reqWidth;
newRect.size.height = reqHeight;
imageView.frame = newRect;

The image will also be resized if the imageview has the contentMode property UIViewContentModeScaleAspectFit .如果 imageview 具有contentMode属性UIViewContentModeScaleAspectFit ,图像也会被调整大小。

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

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