// // BogoLanguageAlertView.m // BuguLive // // Created by 宋晨光 on 2021/5/26. // Copyright © 2021 xfg. All rights reserved. // #import "BogoLanguageAlertView.h" static NSString * const zhongWenJianTi = @"中文简体"; static NSString * const English = @"English"; static NSString * const ALaBoYu = @"بالعربية"; static NSString * const TaiYu = @"ภาษาไทย"; static NSString * const zhongWenFanTi = @"中文繁体"; static NSString * const YueNanYu = @"Tiếng Việt"; static NSString * const RiYu = @"日本語"; @implementation BogoLanguageAlertView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.layer.cornerRadius = 4; self.layer.masksToBounds = YES; self.backgroundColor = kWhiteColor; self.listArr = @[zhongWenJianTi,English,ALaBoYu,TaiYu,zhongWenFanTi,YueNanYu,RiYu]; [self setUpView]; } return self; } -(void)setUpView{ self.titleL = [[UILabel alloc]initWithFrame:CGRectMake(kRealValue(20),kRealValue(10), self.width, kRealValue(40))]; self.titleL.text = ASLocalizedString(@"切换语言"); self.titleL.font = [UIFont systemFontOfSize:20]; [self addSubview:self.titleL]; UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, self.titleL.bottom + kRealValue(15), self.width, kRealValue(self.height - kRealValue(65) - kRealValue(60))) style:UITableViewStylePlain]; tableView.delegate = self; tableView.dataSource = self; tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero]; [self addSubview:tableView]; UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom]; cancleBtn.frame = CGRectMake(0, self.height - kRealValue(50), self.width / 2, kRealValue(40)); [cancleBtn setTitle:ASLocalizedString(@"取消") forState:UIControlStateNormal]; cancleBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [cancleBtn setTitleColor:[UIColor colorWithHexString:@"#0091ea"] forState:UIControlStateNormal]; [cancleBtn addTarget:self action:@selector(clickCancleBtn:) forControlEvents:UIControlEventTouchUpInside]; cancleBtn.titleLabel.font = [UIFont systemFontOfSize:14]; _cancleBtn = cancleBtn; UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom]; confirmBtn.frame = CGRectMake(self.width / 2, self.height - kRealValue(50), self.width / 2, kRealValue(40)); [confirmBtn setTitle:ASLocalizedString(@"确定") forState:UIControlStateNormal]; [confirmBtn setTitleColor:[UIColor colorWithHexString:@"#0091ea"] forState:UIControlStateNormal]; confirmBtn.titleLabel.font = [UIFont systemFontOfSize:14]; [confirmBtn addTarget:self action:@selector(clickConfirmBtn:) forControlEvents:UIControlEventTouchUpInside]; _confirmBtn = confirmBtn; [self addSubview:self.titleL]; [self addSubview:self.tableView]; [self addSubview:self.cancleBtn]; [self addSubview:self.confirmBtn]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.listArr.count; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return kRealValue(40); } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; } cell.textLabel.text = self.listArr[indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // NSArray *languages = [NSLocale preferredLanguages]; NSString *lname = self.listArr[indexPath.row]; NSString *language = @"en"; //简体中文 if([lname isEqualToString:zhongWenJianTi]) { language = @"zh-Hans"; } else if([lname isEqualToString:ALaBoYu]) { //阿拉伯语 language = @"ar"; } else if([lname isEqualToString:English]) { //英语 language = @"en"; } else if([lname isEqualToString:TaiYu]) { //泰语 language = @"th"; } else if([lname isEqualToString:zhongWenFanTi]) { //中文繁体 language = @"zh-Hant"; } else if([lname isEqualToString:YueNanYu]) { //越南语 language = @"vi"; } else if([lname isEqualToString:RiYu]) { //日语 language = @"ja"; } [[LocalizationSystem sharedLocalSystem] setLanguage:language]; //en [BGHUDHelper alert:ASLocalizedString(@"我们将关闭启动程序,请重新启动") action:^{ exit(0); }]; [self.tableView reloadData]; } -(void)clickCancleBtn:(UIButton *)sender{ [self hide]; } -(void)clickConfirmBtn:(UIButton *)sender{ [self hide]; } #pragma mark - Show And Hide - (void)show:(UIView *)superView{ // [self requestModel]; [superView addSubview:self.shadowView]; [superView addSubview:self]; [UIView animateWithDuration:0.25 animations:^{ self.shadowView.alpha = 1; self.y = (kScreenH - self.height) / 2; }]; } - (void)hide{ [UIView animateWithDuration:0.25 animations:^{ self.shadowView.alpha = 0; self.y = kScreenH; } completion:^(BOOL finished) { [self.shadowView removeFromSuperview]; [self removeFromSuperview]; }]; } - (UIView *)shadowView{ if (!_shadowView) { _shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)]; _shadowView.backgroundColor = [kBlackColor colorWithAlphaComponent:0.3]; _shadowView.userInteractionEnabled = YES; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hide)]; [_shadowView addGestureRecognizer:tap]; } return _shadowView; } @end