在我的应用程序中,我使用IBInspectable字符串设置本地化文本,并使用按钮操作手动更改语言。
问题
答案 0 :(得分:0)
我已经使用以下代码:
1. InterFace and Implementation for UIView
@interface UIView (AdditionLocalization)
-(void)applyLocalization;
@end
@implementation UIView (AdditionLocalization)
-(void)applyLocalization{
if ([self isKindOfClass:[UILabel class]]) {
UILabel *lbl = (UILabel *)self;
[lbl setLocalizedText:lbl.accessibilityLabel];
}
}
2. InterFace and Implementation for Label
IB_DESIGNABLE
@interface UILabel(LabelAdditionLocalizations)
@property (nonatomic,copy)IBInspectable NSString *localizedText;
@end
@implementation UILabel(LabelAdditionLocalizations)
@dynamic localizedText;
-(void)setLocalizedText:(NSString *)localizedText{
self.text = [UtilityClass get:localizedText.length>0 ? localizedText : self.text alter:@""];
self.accessibilityLabel = localizedText.length>0 ? localizedText : nil;
}
3.按钮单击时手动触发
- (IBAction)clickChangeLanguage:(id)sender {
[UtilityClass setLanguage:current];
for (UIView *view in self.view.subviews) {
[view applyLocalization];
}
}