将配置图像解析为 UIImageView
Parse Config Image into a UIImageView
我在 Parse.com 上的应用程序 'Config' 中添加了一张图片,但我不确定如何从 'Config' 下载图片并在 UIImageView
中显示下载后在我的应用程序中。
这就是我喜欢 Parse.com 的原因,它们让开发人员的工作变得如此简单。
第 1 步 在 Parse.com 的配置管理员视图中设置参数。对于图像,您必须确保将其设置为 PFFile,并根据您的需要命名。
STEP 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
}
}];
我在 Parse.com 上的应用程序 'Config' 中添加了一张图片,但我不确定如何从 'Config' 下载图片并在 UIImageView
中显示下载后在我的应用程序中。
这就是我喜欢 Parse.com 的原因,它们让开发人员的工作变得如此简单。
第 1 步 在 Parse.com 的配置管理员视图中设置参数。对于图像,您必须确保将其设置为 PFFile,并根据您的需要命名。
STEP 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
}
}];