0

我使用此代码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

4

2 回答 2

0

好的,

我用以下方法修复了它:

var  material = [NSLocalizedString ("Steel", comment: ""),NSLocalizedString ("Aluminum", comment: ""),NSLocalizedString ("Stainless", comment: ""),NSLocalizedString ("Copper", comment: "")]

并使用 localizable.strings。这很好用!

于 2017-10-20T14:36:10.627 回答
0

在 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
    }
于 2017-11-02T05:00:07.120 回答