Skip to content

Instantly share code, notes, and snippets.

@haojianzong
Created May 17, 2015 03:51
Show Gist options
  • Save haojianzong/35619027a1e60754cf99 to your computer and use it in GitHub Desktop.
Save haojianzong/35619027a1e60754cf99 to your computer and use it in GitHub Desktop.
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