gpt4 book ai didi

ios - 将配置图像解析为 UIImageView

转载 作者:行者123 更新时间:2023-11-29 10:33:56 26 4
gpt4 key购买 nike

我在 Parse.com 上的应用“Config”中添加了一张图片,但我不确定如何从“Config”下载图片并在下载后在我的应用的 UIImageView 中显示它.

最佳答案

这就是我喜欢 Parse.com 的原因,它们让开发人员的工作变得如此简单。

第 1 步 在 Parse.com 的配置管理 View 中设置您的参数。对于图像,您必须确保将其设置为 PFFile,并根据您的需要命名。

pic1

第 2 步 在需要调用 Config 参数的任何地方(不限于图像)实现 getConfigInBackground: 方法

[PFConfig getConfigInBackgroundWithBlock:^(PFConfig *config, NSError *error) {
//In my case I have a BOOL statement, that if it is set to false, it won't show the config image I uploaded, it will show a placeholder image stored in the bundle
if ([config[@"bannerisTrue"] boolValue]) {
//The bannerisTrue boolValue is true so that means I want to retrieve the image from Config to display in the app
PFFile *banner1 = config[@"banner1"]; //You reference the image as a PFFile first before retrieving the data, and you're telling the query to specify the config column 'banner1'. Kind of like `selectKeys:`
[banner1 getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
UIImageView *bannerView = [[UIImageView alloc] initWithFrame:/*init how ever you want or place in whatever UIImageView you have a IBOutlet for */];
bannerView.image = [UIImage imageWithData:data]; //Your image is now in the UIImageView that you have set.
}];
} else {
UIImageView *bannerView = [[UIImageView alloc] initWithFrame:/*same frame as above*/];
bannerView.image = [UIImage imageNamed:@"placeholderimage.jpg"]; //Since the boolValue is false we want to have a placeholder image so that way the app is more fluid. This is also good to have in case internet issues arise. This image is the one stored on device
}
}];

关于ios - 将配置图像解析为 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28049482/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com