如何设置图像UIImage [英] How to set image to UIImage

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

问题描述

如何将图像设置为 UIImage 对象。
例如:

How can I set image to UIImage object. For example:

UIImage *img = [[UIImage alloc] init];
[img setImage:[UIImage imageNamed:@"anyImageName"]];

我的 UIImage c $ c> .h 文件并在 init 方法中分配,我需要在 viewDidLoad 方法。
任何想法?

My UIImage object is declared in .h file and allocated in init method, I need to set image in viewDidLoad method. Any ideas?

推荐答案

UIImage *img = [UIImage imageNamed:@"anyImageName"];




imageNamed:

返回与指定文件名相关联的图片对象。

imageNamed:
Returns the image object associated with the specified filename.

    + (UIImage *)imageNamed:(NSString *)name

参数

名称

文件的名称。如果这是第一次加载图像,该方法将在
应用程序的主包中查找具有指定名称的图像。

返回值

指定文件的图片对象,如果方法找不到指定的图片,则为nil。

Parameters
name
The name of the file. If this is the first time the image is being loaded, the method looks for an image with the specified name in the application’s main bundle.
Return Value
The image object for the specified file, or nil if the method could not find the specified image.

讨论 >
此方法查找具有指定名称的图像对象的系统高速缓存,并返回该对象(如果存在)。如果匹配的
图像对象尚未在高速缓存中,则此方法从指定文件加载图像
数据,将其缓存,然后返回
生成的对象。

Discussion
This method looks in the system caches for an image object with the specified name and returns that object if it exists. If a matching image object is not already in the cache, this method loads the image data from the specified file, caches it, and then returns the resulting object.

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

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