objective-c - 如何将图像设置为 UIImage

标签 objective-c ios cocoa-touch

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

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

我的 UIImage 对象在 .h 文件中声明并在 init 方法中分配,我需要在 viewDidLoad< 中设置图像 方法。 有什么想法吗?

最佳答案

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

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

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

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.

关于objective-c - 如何将图像设置为 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10931510/

相关文章:

iphone - 获取当前调度队列?

ios - 在 Mac 上使用 SwiftUI App Lifecycle 时,@UIApplicationMain 只能用于 'class' 声明错误

iphone - NSCachesDirectory 不是我的文件系统中的目录

objective-c - 我在UIActivityGroupViewController中遇到各种崩溃,这是UIDocumentInteractionController和UIActivityViewController的一部分

ios - Plist 值被替换而不是添加

ios - SLComposeViewController 不正确的结果

ios LINESTRING 解析

objective-c - NSUndoManager 使用旋转手势撤销 UIImage 旋转

iphone - UIWebView 中的 ScrollOffset?

ios - 你如何创建 UITextField 的子类?