0

I used this code in Objective C to change language in a 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];
}

How can i do this in Swift, or is there another way to translate text in a PickerView. Sorry for this stupid question but I´m really a beginner with Swift.

alexander.polomodov
  • 5,396
  • 14
  • 39
  • 46
Uwe
  • 1

2 Answers2

0

Ok,

i fixed it with:

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

and use localizable.strings. That works fine!

Uwe
  • 1
0

In 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
    }
Amul4608
  • 1,390
  • 14
  • 30