iOS Storyboard 可本地化字符串不适用于 UILabel 子类

标签 ios fonts localization translation uistoryboard

我正在使用新的 iOS 功能来翻译 Storyboard (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-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 文件中获取自动翻译的东西。

有人有想法吗?

谢谢!

最佳答案

我遇到了同样的问题,出于同样的原因,在标签中设置了自定义字体。不过,我的策略有点笼统。我的自定义字体是 Helvetica-like,所以我使用 IB 中的 Helvetica Neue 作为占位符字体。 UILabel 子类将其转换为我的自定义字体,保留字体大小和粗细,因此我可以通过 IB 控制所有这些。

这让我更容易解决翻译错误(我认为这是一个错误)。我在 viewDidLoad 中递归地遍历所有 View ,并映射所有 UILabel 字体(如果它们与占位符字体匹配),在我的例子中也映射 UIButton。

你有提交错误吗?

关于iOS Storyboard 可本地化字符串不适用于 UILabel 子类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16928670/

相关文章:

ios - 奇怪的快速插值错误 : Could not find member 'convertFromStringInterpolationSegment'

android - 如何在安卓模拟器中为印度地方语言设置自定义语言环境

ios - 当连接由 iOS 8.3 供电的设备时,设备在 Xcode 6.1 中不合格

ios - 从 accessibilityLabel 获取 UIVIew 用于 KIF 自动化

html - 使用由宽度定义的 Font Awesome 星级

c# - C#-与设计有关的配置问题(两个)

javascript - 网络日期的国际化

php - Laravel 不区分大小写的本地化

ios - 如何在没有 Storyboard的情况下创建 UNNotificationContentExtension?

linux - 如何使用免费的 Linux 命令行工具将字体嵌入到 PDF 中?