如何使用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];
}