我有一个类输出取决于当天的字符串。它在俄语中工作得很好,但是,当我切换到另一种语言时,它就不起作用了。我是这样写的:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEEE"];
// Current day
NSString *currentDay = [dateFormatter stringFromDate:[NSDate date]];
// Mon
if ([currentDay isEqualToString:@"понедельник"]){
_mon.textColor = COLOR_BG;
}
是否有任何简单的方法可以使该代码在其他语言中工作?不依赖于当前 iPhone 选择的语言?
最佳答案
您在这里比较的字符串对于另一种语言是不同的。
所以你要么有每个工作日语言的翻译,要么我推荐的方法是更改格式化程序以返回一周的整数。如果我没记错是e
所以会是:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"e"];
int current = [[dayDateFormatter stringFromDate:[NSDate date]] intValue];
if (currentDay == 1){
_mon.textColor = COLOR_BG;
}
关于ios - 检查不同语言的工作日字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38698135/