如何在Swift中设置图像的宽度和高度 [英] How do set a width and height of an Image in Swift

查看:430
本文介绍了如何在Swift中设置图像的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的 Swift iOS 一般编程。我无法弄清楚如何设置图像的宽度和高度。

例如,

New to Swift and iOS programming in general. I couldn't figure out how to set a width and height of an image.
For example,

  let backgroundImage = UIImage(named: "background.png")

谢谢

推荐答案

我的建议是。

而不是设置图片的大小你应该设置 UIImageView 的大小,然后将图像放在上面,这样,图像的大小将显示为根据您的要求。

Instead of set size of image you should set size of UIImageView and then put this image on it so, size of image will be display as per your requirement.

如此,

var imageView = UIImageView(frame: CGRectMake(100, 150, 150, 150)); // set as you want
var image = UIImage(named: "myImage.png");
imageView.image = image;
self.view.addSubview(imageView);

这篇关于如何在Swift中设置图像的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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