我需要设置语言
我有:
#define kMenuSettingsHeaderrus @"Настройки"
#define kMenuSettingsHeadereng @"Settings"
我希望使用这个全局变量将字符串设置为标签,具体取决于
_language= [[SettingsManager sharedSettingsManager] getLanguage];
_language can be @"rus" or @"eng"
CCLabelTTF *settingsLabel = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"kMenuSettingsHeader%@",_language] fontName:kLabelFontNameTTF fontSize:kMenuHeaderFontSize];
你可以帮助我,在php中我这样做就像$$
来自php的一个例子:
$a = "hello";
$$a = "world"; => $hello="world"
答案 0 :(得分:1)
您正在做的事情会给出kMenuSettingsHeadereng或kMenuSettingsHeaderrus作为结果,因为它们将被视为字符串而不是宏...所以使用此
#define kMenuSettingsHeaderrus @"Настройки"
#define kMenuSettingsHeadereng @"Settings"
_language= [[SettingsManager sharedSettingsManager] getLanguage];
CCLabelTTF *settingsLabel;
if ([_langueage isEqualToString:@"rus"])
{
settingsLabel = [CCLabelTTF labelWithString:kMenuSettingsHeaderrus fontName:kLabelFontNameTTF fontSize:kMenuHeaderFontSize];
}
else if ([_langueage isEqualToString:@"eng"])
{
settingsLabel = [CCLabelTTF labelWithString:kMenuSettingsHeadereng fontName:kLabelFontNameTTF fontSize:kMenuHeaderFontSize];
}
检查语法...我没有X代码来检查...希望这会有所帮助.. :)