UIImageView改变宽度和高度 [英] UIImageView change Width and Height

查看:808
本文介绍了UIImageView改变宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里阅读了各种帖子,询问类似的问题......我尝试了各种方式发布,包括边界和框架等,包括以下内容:

I've read various posts on here asking similar questions... I've tried various ways that were posted including bounds and frames etc. including the following:

myImage.frame = CGRectMake(0.0f, 0.0f,50.0f, 50.0f);

和:

myImage.bounds = CGRectMake(0.0f, 0.0f,50.0f, 120.0f);

这些都不起作用。

但是,我觉得有趣的是下面的代码让我移动图像但不改变宽度:

However, I find it interesting that the following code let's me move the Image around but doesn't change the width:

CGRect frameRect = myImage.frame;
frameRect.size.width = 50.0f;
frameRect.origin.x += 10.5f;
myImage.frame = frameRect;

那么为什么这些都不会改变我的ImageView的宽度/高度?

So why don't any of these change the width/height of my ImageView?

我在这里找到了另一篇文章,基本上说我必须修改一小段代码来调整我的图像大小...这是真的吗?

I found another post on here that basically states I have to right a small book of code to get it resize my image... is that true?

比如这个:
UIImage:Resize,然后裁剪

当然这比那简单吗?

推荐答案

以下内容将更改UIImaveView的大小,剪切基础图像而不调整其大小并使其保持与视图左下角对齐:

The following will change the size of the UIImaveView, clipping the underlying image without resizing it and keeping it aligned to bottom left of view:

imageView.frame = CGRectMake(
             imageView.frame.origin.x, 
             imageView.frame.origin.y, newWidth, newHeight);

imageView.contentMode = UIViewContentModeBottomLeft; // This determines position of image
imageView.clipsToBounds = YES;

这篇关于UIImageView改变宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆