Xcode的新功能。我有一个创建视图的静态库,但是我想允许一个新项目在配置文件中设置视图框架,该配置文件可以更改静态库中的框架大小值。某种全局的#define变量。
如何在Xcode中做到这一点?我研究了pbxuser文件,pch,xconfigs和plists,但是对于应该在哪里进行设置完全迷失了。
最佳答案
假设您的config.plist文件位于项目文件夹下并添加到项目中:
NSString *configPath = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
NSDictionary *config = [NSDictionary dictionaryWithContentsOfFile:configPath];
float xStartPoint = [[config objectForKey:@"xStartPoint"] floatValue];
float yStartPoint = [[config objectForKey:@"yStartPoint"] floatValue];
float objectWidth = [[config objectForKey:@"objectWidth"] floatValue];
float objectHeight = [[config objectForKey:@"objectHeight"] floatValue];
UIView *exampleView = [[UIView alloc] initWithFrame:CGRectMake(xStartPoint, yStartPoint, objectWidth, objectHeight)];
[self.view addSubview:exampleView];
Plist文件的示例:
The .plist code
关于ios - 在Xcode中创建配置文件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26896279/