我在Objective C中使用此代码更改了PickerView中的语言
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.dicke = [[NSArray alloc]
initWithObjects:@"0.0",@"0.5",@"1.0",@"1.5",@"2.0",@"2.5",@"3.0",@"4.0",@"5.0",@"6.0",@"8.0",@"10.0",@"12.0",@"15.0",@"20.0", nil];
NSString *userLocale = [[NSLocale currentLocale] localeIdentifier];
NSLog(@"%@", userLocale);
if ([userLocale isEqualToString:@"de_DE"]) {
self.Material = [[NSArray alloc]
initWithObjects:@"Stahl",@"Aluminium",@"Edelstahl",@"Kupfer", nil];
}
else
self.Material = [[NSArray alloc]
initWithObjects:@"Steel",@"Aluminum",@"Stainless",@"Copper", nil];
}我如何在Swift中做到这一点,或者是否有其他方法来翻译PickerView中的文本。对于这个愚蠢的问题我很抱歉,但我真的是Swift的初学者。
发布于 2017-10-20 22:36:11
好的,
我用以下命令修复了它:
var material = [NSLocalizedString ("Steel", comment: ""),NSLocalizedString ("Aluminum", comment: ""),NSLocalizedString ("Stainless", comment: ""),NSLocalizedString ("Copper", comment: "")]并使用localizable.strings。这很好用!
发布于 2017-11-02 13:00:07
Swift 3.0中的
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let pickerLabel = UILabel()
pickerLabel.textColor = (row == pickerView.selectedRow(inComponent: component)) ? UIColor.white : UIColor.white
pickerLabel.text = arrAgeLimite[row]
pickerLabel.font.withSize(90)
pickerLabel.textAlignment = NSTextAlignment.center
return pickerLabel
}https://stackoverflow.com/questions/46775995
复制相似问题