使用UIPicker IOS以编程方式更改语言

时间:2014-02-21 07:02:12

标签: ios localization internationalization

如何使用UIPicker更改IOS中的语言?

语言:英语,中文(简体),马来西亚语

当用户选择中文(简体)时,它会根据上述语言更改标签的内容。

这是代码

ChangeLanguage.h

@interface ChangeLanguageViewController :UIViewController<UIPickerViewDataSource UIPickerViewDelegate>
@property (nonatomic, strong)IBOutlet UIPickerView *myPickerView;
@oroperty (nonatomic, strong)NSArray *languageArray;

#import "ChangeLanguageViewController.h"

@interface ChangeLanguageViewController ()

@end

- (void)viewDidLoad
{

myPickerView.delegate = self;
myPickerView.dataSource = self;

languageArray = [[NSArray alloc] initWithObjects:@"English", @"Chinese (Simplified)", @"Bahasa
 Malaysia", nil];
#pragma mark - UIPickerView Delegate
//return the number of columns to display
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
//returns the number of rows in each component.
-(NSInteger)pickerView:(UIPicker *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [languageArray count];

#pragma mark -UIPickerView Delegate
-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
return 30.0;
}
-(NSString *)pickerView:(UIPicker *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [languageArray objectAtIndex:row];
}

0 个答案:

没有答案