2016-10-06 7 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 수동으로