2016-08-01 24 views
0

我有一個依賴當前日期的輸出字符串的類。它在俄羅斯工作很好,但是,當我切換到另一種語言不工作。這就是我寫的:檢查不同語言的星期字符串

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選擇語言?

回答

1

您正在比較另一種語言不同的字符串。

因此,您要麼爲每個週日語言翻譯,要麼我推薦的方法是更改​​格式化程序以返回一週中的整數。如果我沒看錯是Ë

因此,這將是:

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"e"]; 
int current = [[dayDateFormatter stringFromDate:[NSDate date]] intValue]; 

if (currentDay == 1){ 
    _mon.textColor = COLOR_BG; 
} 
+0

如何使代表星期幾號一個int? –

+0

我更新了它。是我的頭頂,可能會有一些錯誤。 –

+0

好吧我稍後再試,謝謝) –