2016-10-06 3 views
-1

私のアプリでは、ローカライズテキストをIBInspectable文字列を使用して設定し、ボタン操作を使用して手動で言語を変更します。ローカライゼーションに関するIBInspectableに関する問題について

問題

  1. 私は手動で変更言語ながら、UIを更新することはできませんすることができます。言語を変更しているときにIBInspectable文字列を更新する必要があります。

答えて

0

私はコードの下に使用して達成している:ボタン

- (IBAction)clickChangeLanguage:(id)sender { 
    [UtilityClass setLanguage:current]; 
    for (UIView *view in self.view.subviews) { 
     [view applyLocalization]; 
    } 
} 
をクリックしながら

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.Trigger手動