iOS Storyboard可本地化的字符串在UILabel子类中不起作用 [英] iOS Storyboard localizable strings do not work on UILabel subclasses
问题描述
我使用新的iOS功能来翻译故事板( http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/chapters/InternationalizeYourApp/InternationalizeYourApp/InternationalizeYourApp.html )
这个解决方案的问题,它不适用于我的UILabel子类。
这是我的UILabel子类的代码:
.h:
#import< UIKit / UIKit.h>
@interface LabelThinText:UILabel
- (void)awakeFromNib;
- (id)initWithFrame:(CGRect)frame;
@end
.m:
@implementation LabelThinText
- (void)awakeFromNib
{
[super awakeFromNib];
[self setFont:[UIFont fontWithName:@Raleway-Lightsize:[[self font] pointSize]]];
$ b $ - (id)initWithFrame:(CGRect)frame
{
id result = [super initWithFrame:frame];
if(result){
[self setFont:[UIFont fontWithName:@Raleway-Lightsize:[[self font] pointSize]]];
}
返回结果;
}
@end
我猜我缺少从$ Storyboard.strings文件中获取自动翻译。
遇到同样的问题,我是这样解决的:
<
- (void)setThinText(UILabel + ThinText)将您的自定义类放在UILabel上创建一个类别, :(BOOL)thinText
{
if(thinText){
[self setFont:[UIFont fontWithName:@Raleway-Lightsize:[[self font] pointSize]]];
在你的故事板中,选择你的标签,选择身份检查器,并添加以下用户定义的运行时属性:
$ b Keypath :thinText - 类型:布尔值 - 值:已选中
I'm using the new iOS functionnality to translate the storyboards (http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/chapters/InternationalizeYourApp/InternationalizeYourApp/InternationalizeYourApp.html)
The problem with this solution, it does not work with my UILabel subclasses.
Here are the codes for my UILabel subclasses :
.h:
#import <UIKit/UIKit.h>
@interface LabelThinText : UILabel
- (void)awakeFromNib;
-(id)initWithFrame:(CGRect)frame;
@end
.m :
@implementation LabelThinText
- (void)awakeFromNib
{
[super awakeFromNib];
[self setFont:[UIFont fontWithName:@"Raleway-Light" size:[[self font] pointSize]]];
}
-(id)initWithFrame:(CGRect)frame
{
id result = [super initWithFrame:frame];
if (result) {
[self setFont:[UIFont fontWithName:@"Raleway-Light" size:[[self font] pointSize]]];
}
return result;
}
@end
I guess i'm missing something to get the automatic translations from my Storyboard.strings file.
Anyone has an idea ?
Thanks !
解决方案 Encountered the same problem, here's how I got around it:
Drop your custom class, and create a category on UILabel, in your case UILabel+ThinText:
- (void) setThinText:(BOOL)thinText
{
if (thinText) {
[self setFont:[UIFont fontWithName:@"Raleway-Light" size:[[self font] pointSize]]];
}
}
In your storyboard, select your label, choose the Identity Inspector and add the following User Defined Runtime Attribute:
Keypath: thinText – Type: Boolean – Value: checked
这篇关于iOS Storyboard可本地化的字符串在UILabel子类中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!