我有一个 .xib
文件,随附 .strings
不同语言的文件。 .xib
文件包含一个标签和一个 UISegmentedControl
.
当要求 IB 本地化 .xib
时文件,我得到以下 .strings
文件:
"6.segmentTitles[0]" = "title1";
// ...More strings related to the segmented control...
"11.text" = "bla";
'bla' 字符串属于标签。
更改 'bla` 字符串会反射(reflect)在运行时,而更改 'title1' 字符串不会。有谁知道为什么?
最佳答案
这个问题并不新鲜,但由于它仍然没有任何答案,我将添加我的解决方案,因为它可能会帮助其他人。
一般来说,正如上面提到的,UISegmentedControl 段标题不选择本地化字符串是一个开放的错误。
- (void)viewDidLoad
{
...
// Locale will be picked automatically by NSBundle.
NSString *resourcePath =[[NSBundle mainBundle] pathForResource:@"MainStoryboard" ofType:@"strings"];
NSDictionary *resourceDict = [NSDictionary dictionaryWithContentsOfFile:resourcePath];
[self.segmentedControl setTitle:[resourceDict objectForKey:@"COo-BO-Ryl.segmentTitles[0]"] forSegmentAtIndex:0];
[self.segmentedControl setTitle:[resourceDict objectForKey:@"COo-BO-Ryl.segmentTitles[1]"] forSegmentAtIndex:1];
}
哪里
COo-BO-Ryl
是 segmentedControl 的对象 ID。不是很漂亮,但可以完成工作。
关于localization - UISegmentedControl 和本地化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12884751/