BogoLanguageAlertView.m 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. //
  2. // BogoLanguageAlertView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/5/26.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoLanguageAlertView.h"
  9. static NSString * const zhongWenJianTi = @"中文简体";
  10. static NSString * const English = @"English";
  11. static NSString * const ALaBoYu = @"بالعربية";
  12. static NSString * const TaiYu = @"ภาษาไทย";
  13. static NSString * const zhongWenFanTi = @"中文繁体";
  14. static NSString * const YueNanYu = @"Tiếng Việt";
  15. static NSString * const RiYu = @"日本語";
  16. @implementation BogoLanguageAlertView
  17. - (instancetype)initWithFrame:(CGRect)frame
  18. {
  19. self = [super initWithFrame:frame];
  20. if (self) {
  21. self.layer.cornerRadius = 4;
  22. self.layer.masksToBounds = YES;
  23. self.backgroundColor = kWhiteColor;
  24. self.listArr = @[zhongWenJianTi,English,ALaBoYu,TaiYu,zhongWenFanTi,YueNanYu,RiYu];
  25. [self setUpView];
  26. }
  27. return self;
  28. }
  29. -(void)setUpView{
  30. self.titleL = [[UILabel alloc]initWithFrame:CGRectMake(kRealValue(20),kRealValue(10), self.width, kRealValue(40))];
  31. self.titleL.text = ASLocalizedString(@"切换语言");
  32. self.titleL.font = [UIFont systemFontOfSize:20];
  33. [self addSubview:self.titleL];
  34. UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, self.titleL.bottom + kRealValue(15), self.width, kRealValue(self.height - kRealValue(65) - kRealValue(60))) style:UITableViewStylePlain];
  35. tableView.delegate = self;
  36. tableView.dataSource = self;
  37. tableView.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
  38. [self addSubview:tableView];
  39. UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  40. cancleBtn.frame = CGRectMake(0, self.height - kRealValue(50), self.width / 2, kRealValue(40));
  41. [cancleBtn setTitle:ASLocalizedString(@"取消") forState:UIControlStateNormal];
  42. cancleBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  43. [cancleBtn setTitleColor:[UIColor colorWithHexString:@"#0091ea"] forState:UIControlStateNormal];
  44. [cancleBtn addTarget:self action:@selector(clickCancleBtn:) forControlEvents:UIControlEventTouchUpInside];
  45. cancleBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  46. _cancleBtn = cancleBtn;
  47. UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  48. confirmBtn.frame = CGRectMake(self.width / 2, self.height - kRealValue(50), self.width / 2, kRealValue(40));
  49. [confirmBtn setTitle:ASLocalizedString(@"确定") forState:UIControlStateNormal];
  50. [confirmBtn setTitleColor:[UIColor colorWithHexString:@"#0091ea"] forState:UIControlStateNormal];
  51. confirmBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  52. [confirmBtn addTarget:self action:@selector(clickConfirmBtn:) forControlEvents:UIControlEventTouchUpInside];
  53. _confirmBtn = confirmBtn;
  54. [self addSubview:self.titleL];
  55. [self addSubview:self.tableView];
  56. [self addSubview:self.cancleBtn];
  57. [self addSubview:self.confirmBtn];
  58. }
  59. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  60. return 1;
  61. }
  62. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  63. return self.listArr.count;
  64. }
  65. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  66. return kRealValue(40);
  67. }
  68. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  69. static NSString *identifier = @"cell";
  70. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  71. if (!cell) {
  72. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
  73. }
  74. cell.textLabel.text = self.listArr[indexPath.row];
  75. return cell;
  76. }
  77. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  78. // NSArray *languages = [NSLocale preferredLanguages];
  79. NSString *lname = self.listArr[indexPath.row];
  80. NSString *language = @"en";
  81. //简体中文
  82. if([lname isEqualToString:zhongWenJianTi])
  83. {
  84. language = @"zh-Hans";
  85. } else if([lname isEqualToString:ALaBoYu]) {
  86. //阿拉伯语
  87. language = @"ar";
  88. } else if([lname isEqualToString:English]) {
  89. //英语
  90. language = @"en";
  91. } else if([lname isEqualToString:TaiYu]) {
  92. //泰语
  93. language = @"th";
  94. } else if([lname isEqualToString:zhongWenFanTi]) {
  95. //中文繁体
  96. language = @"zh-Hant";
  97. } else if([lname isEqualToString:YueNanYu]) {
  98. //越南语
  99. language = @"vi";
  100. } else if([lname isEqualToString:RiYu]) {
  101. //日语
  102. language = @"ja";
  103. }
  104. [[LocalizationSystem sharedLocalSystem] setLanguage:language];
  105. //en
  106. [BGHUDHelper alert:ASLocalizedString(@"我们将关闭启动程序,请重新启动") action:^{
  107. exit(0);
  108. }];
  109. [self.tableView reloadData];
  110. }
  111. -(void)clickCancleBtn:(UIButton *)sender{
  112. [self hide];
  113. }
  114. -(void)clickConfirmBtn:(UIButton *)sender{
  115. [self hide];
  116. }
  117. #pragma mark - Show And Hide
  118. - (void)show:(UIView *)superView{
  119. // [self requestModel];
  120. [superView addSubview:self.shadowView];
  121. [superView addSubview:self];
  122. [UIView animateWithDuration:0.25 animations:^{
  123. self.shadowView.alpha = 1;
  124. self.y = (kScreenH - self.height) / 2;
  125. }];
  126. }
  127. - (void)hide{
  128. [UIView animateWithDuration:0.25 animations:^{
  129. self.shadowView.alpha = 0;
  130. self.y = kScreenH;
  131. } completion:^(BOOL finished) {
  132. [self.shadowView removeFromSuperview];
  133. [self removeFromSuperview];
  134. }];
  135. }
  136. - (UIView *)shadowView{
  137. if (!_shadowView) {
  138. _shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  139. _shadowView.backgroundColor = [kBlackColor colorWithAlphaComponent:0.3];
  140. _shadowView.userInteractionEnabled = YES;
  141. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hide)];
  142. [_shadowView addGestureRecognizer:tap];
  143. }
  144. return _shadowView;
  145. }
  146. @end