문제

i am coding a program for iPhone using Xcode. i defined some attributes for user interface components like uibutton, uilabel etc in property list file. i defined one attribute as real named "cornerradius". Now, how can i get this value from plist correctly to assign CGFloat? Is property list the best way to define attributes? what are my options, any tutorials you recommend?

in plist: key cornerradius /key real 6.0 /real

in code:

NSDecimal cornerRadius;
cornerRadius = [[[dao libraryItemAtIndex:0] valueForKey:@"cornerradius"] decimalValue];
[layer setCornerRadius:(CGFloat)cornerRadius];
도움이 되었습니까?

해결책

If you are looking for program wide scope you should use NSUserDefaultsController , keep in mind that with a plist you will be only be able to store and retrieve values, like NSNumber, NSString, NSArray, NSDictionary...

NSUserDefaults * standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults setObject:[NSNumber numberWithInt:7] forKey:@"someKey"];
[standardUserDefaults synchronize];//save to disk
// now use it
NSNumber * someNumber = [standardUserDefaults objectForKey:@"someKey"];
int someInt = [someNumber intValue];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top