Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Category to Set LocalizedString for Xib Files in User Define Runtime Attributes
//
// UIView+JZLocalizedIB.m
//
// Created by haojianzong on 12/5/17.
//
// A Category to Set LocalizedString for Xib Files in User Define Runtime Attributes
#import <UIKit/UIKit.h>
#import "JZLocaleUtils.h"
@interface UIButton (JZLocalizedIB)
@property (nonatomic, copy) NSString* localizedString;
@end
@implementation UIButton (JZLocalizedIB)
- (NSString *)localizedString {
return self.titleLabel.text;
}
- (void)setLocalizedString:(NSString *)localizedString {
[self setTitle:[JZLocaleUtils localizedString:localizedString]
forState:UIControlStateNormal];
}
@end
@interface UILabel (JZLocalizedIB)
@property (nonatomic, copy) NSString* localizedString;
@end
@implementation UILabel (JZLocalizedIB)
- (NSString *)localizedString {
return self.text;
}
- (void)setLocalizedString:(NSString *)localizedString {
self.text = [JZLocaleUtils localizedString:localizedString];
}
@end
@interface UITextField (JZLocalizedIB)
@property (nonatomic, copy) NSString* localizedString;
@end
@implementation UITextField (JZLocalizedIB)
- (NSString *)localizedString {
return self.text;
}
- (void)setLocalizedString:(NSString *)localizedString {
self.text = [JZLocaleUtils localizedString:localizedString];
}
@end
@interface UITextView (JZLocalizedIB)
@property (nonatomic, copy) NSString* localizedString;
@end
@implementation UITextView (JZLocalizedIB)
- (NSString *)localizedString {
return self.text;
}
- (void)setLocalizedString:(NSString *)localizedString {
self.text = [JZLocaleUtils localizedString:localizedString];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment