在 objective-c 中,如何上传和查询 UIColor 以进行解析?我一直在尝试很多特别的事情,但没有结果。我能够将 UIColor 转换为 NSData 并将其保存到 PFFile。但是我没有运气查询该文件。
在这一点上,我不知道我做的是否正确。请帮忙。
最佳答案
试试这个……它会起作用
PFObject *colorObj = [PFObject objectWithClassName:@"Colors"];
CIColor *color = [CIColor colorWithRed:155.0/255 green:172.0/255 blue:57.0/255 alpha:1.0];
colorObj[@"redColor"] = [NSNumber numberWithFloat:color.red];
colorObj[@"greenColor"] = [NSNumber numberWithFloat:color.green];
colorObj[@"blueColor"] = [NSNumber numberWithFloat:color.blue];
colorObj[@"forView"] = @"Label";
NSError *error;
BOOL isSaved = [colorObj save:&error];
if (isSaved) {
//saved
} else {
//error
}
PFQuery *query = [PFQuery queryWithClassName:@"Colors"];
NSArray *arr = [query findObjects];
NSInteger index = 0;
while (index < arr.count) {
//getting view type to assign color
NSString *viewType = [arr objectAtIndex:index][@"forView"];
if ([viewType isEqualToString:@"Label"]) {
//geeting color
CGFloat red = [arr[index][@"redColor"] floatValue];
CGFloat green = [arr[index][@"greenColor"] floatValue];
CGFloat blue = [arr[index][@"blueColor"] floatValue];
self.myLabel.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
}
index++;
}
关于ios - 如何上传和查询颜色以解析 iOS/objective c,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30971719/