NSUserDefaults 保存颜色
1、保存
CGFloat a = random()%255/255.0;
CGFloat b = random()%255/255.0;
CGFloat c = random()%255/255.0;
UIColor *textDefaultColor = [UIColor colorWithRed:a green:b blue:c alpha:1 ];
CGColorRef colorRef = textDefaultColor.CGColor;
NSString *colorStr = [CIColor colorWithCGColor:colorRef].stringRepresentation;
[[NSUserDefaults standardUserDefaults] setObject:colorStr forKey:@"color"];
[[NSUserDefaults standardUserDefaults] synchronize];
2、读取
NSString *colorStr = [[NSUserDefaults standardUserDefaults] objectForKey:@"color"];
CIColor *colorRef = (CIColor *)[CIColor colorWithString:colorStr];
self.view.backgroundColor = [UIColor colorWithCIColor:colorRef];