iOS Storyboard 可本地化字符串不适用于 UILabel 子类 [英] iOS Storyboard localizable strings do not work on UILabel subclasses

查看:32
本文介绍了iOS Storyboard 可本地化字符串不适用于 UILabel 子类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用新的 iOS 功能来翻译故事板(http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/chapters/InternationalizeYourApp/InternationalizeYourApp/InternationalizeYourApp.html)

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)

这个解决方案的问题,它不适用于我的 UILabel 子类.

The problem with this solution, it does not work with my UILabel subclasses.

这是我的 UILabel 子类的代码:

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    

我想我缺少一些东西来从我的 Storyboard.strings 文件中获取自动翻译.

I guess i'm missing something to get the automatic translations from my Storyboard.strings file.

有人有想法吗?

谢谢!

推荐答案

遇到了同样的问题,我是这样解决的:

Encountered the same problem, here's how I got around it:

删除您的自定义类,并在 UILabel 上创建一个类别,在您的情况下为 UILabel+ThinText:

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]]];
    }
}

在您的故事板中,选择您的标签,选择 Identity Inspector 并添加以下用户定义的运行时属性:

In your storyboard, select your label, choose the Identity Inspector and add the following User Defined Runtime Attribute:

Keypath:thinText – Type:布尔值 – Value:选中

Keypath: thinText – Type: Boolean – Value: checked

这篇关于iOS Storyboard 可本地化字符串不适用于 UILabel 子类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆