我正在使用新的 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/