Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

快速地将控件文本转换成NSLocalizedString #3

Open
xaoxuu opened this issue Apr 25, 2017 · 0 comments
Open

快速地将控件文本转换成NSLocalizedString #3

xaoxuu opened this issue Apr 25, 2017 · 0 comments

Comments

@xaoxuu
Copy link
Owner

xaoxuu commented Apr 25, 2017

用法示例

// 将self.testView中所有的UILabel中的文字转换支持多语言
[self.testView ax_eachSubview:[UILabel class] action:^(__kindof UIView * _Nonnull subview) {
    UILabel *lb = subview;
    AXLocalizedLabel(lb);
}];
// 将self.testView中所有的UITextField中的文字转换支持多语言
[self.local ax_eachSubview:[UITextField class] action:^(__kindof UIView * _Nonnull subview) {
    UITextField *tf = subview;
    AXLocalizedTextField(tf);
}];
// 将self.testView中所有的UITextView中的文字转换支持多语言
[self.local ax_eachSubview:[UITextView class] action:^(__kindof UIView * _Nonnull subview) {
    UITextView *tv = subview;
    AXLocalizedTextView(tv);
}];

注意:此方法生效的前提是你的Localizable.strings文件中有这些语言的翻译。

接口

/**
 将UILabel中的文字转换成NSLocalizedString

 @param label 目标UILabel
 */
FOUNDATION_EXTERN void AXLocalizedLabel(UILabel *label);

/**
 将UITextView中的文字转换成NSLocalizedString
 
 @param textView 目标UITextView
 */
FOUNDATION_EXTERN void AXLocalizedTextView(UITextView *textView);

/**
 将UITextField中的文字转换成NSLocalizedString
 
 @param textField 目标UITextField
 */
FOUNDATION_EXTERN void AXLocalizedTextField(UITextField *textField);

实现

inline void AXLocalizedLabel(UILabel *label){
    label.text = NSLocalizedString(label.text, nil);
}

inline void AXLocalizedTextView(UITextView *textView){
    textView.text = NSLocalizedString(textView.text, nil);
}

inline void AXLocalizedTextField(UITextField *textField){
    textField.placeholder = NSLocalizedString(textField.placeholder, nil);
    textField.text = NSLocalizedString(textField.text, nil);
}
This was referenced Apr 28, 2017
@xaoxuu xaoxuu added the help label Jun 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant