Well , you could save the RGB of the color. And the font-name of the font.
So when you're saving , store these values for font: font.fontName
, font.pointSize
and RGB of the color. Here you can see how to get the RGB of a UIColor
object.
These are all NSString and float values so you shouldn't have any problem in saving them.
- (NSString *) pahtForFile:(NSString*) filename
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:filename];
}
- (void) save
{
//get RGB and fontName , fontSize like I explained above
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[dictionary setObject:fontName forKey:@"fontName"];
[dictionary setObject:[NSNumber numberWithFloat:fontSize] forKey:@"fontSize"];
[dictionary setObject:[NSNumber numberWithFloat:red] forKey:@"red"];
[dictionary setObject:[NSNumber numberWithFloat:green] forKey:@"green"];
[dictionary setObject:[NSNumber numberWithFloat:blue] forKey:@"blue"];
NSString *filepath = [self pathForFile:@"save.plist"];
[dictionary writeToFile:filepath atomically:TRUE];
}
- (void) load
{
float red,green,blue,fontSize;
NSString *fontName;
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:[self pahtForFile:@"save.plist"]];
red = [[dictionary objectForKey:@"red"] floatValue];
green = [[dictionary objectForKey:@"green"] floatValue];
blue = [[dictionary objectForKey:@"blue"] floatValue];
fontSize = [[dictionary objectForKey:@"fontSize"] floatValue];
fontName = [dictionary objectForKey:@"fontName"];
//now rebuild color and font like this:
UIColor *color = [UIColor colorWithRed:red green:green blue:blue alpha:1];
UIFont *font = [UIFont fontWithName:fontName size:fontSize];
}
Hope this helps.
BTW: If you find the answer useful , mark it as correct.
Cheers,
George