UIImage 的路径是什么
What is the path of a UIImage
我正在使用 UIImage
class 初始化程序 init(contentsOfFile:)
。但是我应该如何指定确切的路径。比如我在我的mac的桌面上保存了一张名为"Picture"的图片,那么我该如何使用这张图片呢?只是 "Picture.png"
或 "/Users/Username/Desktop/Picture.png"
,或者我必须将该图片保存在特定文件夹中?
执行以下操作:
- 将文件 "picture.png" 添加到您的项目。
- 使用 UIImage 的 imageNamed 方法 class 引用文件。
喜欢(对于 obj-c):
UIImage *image = [UIImage imageNamed:@"picture"];
或(对于swift):
let image = UIImage(named:"picture")
应该可以。
我正在使用 UIImage
class 初始化程序 init(contentsOfFile:)
。但是我应该如何指定确切的路径。比如我在我的mac的桌面上保存了一张名为"Picture"的图片,那么我该如何使用这张图片呢?只是 "Picture.png"
或 "/Users/Username/Desktop/Picture.png"
,或者我必须将该图片保存在特定文件夹中?
执行以下操作:
- 将文件 "picture.png" 添加到您的项目。
- 使用 UIImage 的 imageNamed 方法 class 引用文件。
喜欢(对于 obj-c):
UIImage *image = [UIImage imageNamed:@"picture"];
或(对于swift):
let image = UIImage(named:"picture")
应该可以。