2013-06-04 51 views
5

我使用的是全新的iOS functionnality翻譯的故事板(http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/chapters/InternationalizeYourApp/InternationalizeYourApp/InternationalizeYourApp.htmliOS的故事板本地化字符串不上工作的UILabel子類

這種解決方案的問題,它不與我的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文件。

任何人有想法?

謝謝!

+0

您可以下載我的測試項目:https://github.com/arn00s/iOS_BaseLocalization只需將設備lang從EN切換到FR,即可看到不同之處。 –

回答

1

我遇到了同樣的問題,並出於同樣的原因,在標籤中設置自定義字體。不過,我的策略比較一般。我的自定義字體是類似Helvetica的,所以我在IB中使用Helvetica Neue作爲佔位符字體。 UILabel子類將其轉換爲我的自定義字體,保留了字體大小和重量,所以我可以通過IB控制所有的字體。

這使我的翻譯錯誤(我認爲這是一個錯誤)的解決方法更容易。我在viewDidLoad中遞歸遍歷所有視圖,並映射所有UILabel字體(如果它們與佔位符字體相匹配),而在我的情況下,它們與UIButton相同。

你提交了一個錯誤?

+1

我沒有提交錯誤,但我要求Apple提供技術支持。他們告訴我他們必須仔細查看一名工程師(1個月前)。仍在等待答覆... –

+3

我有類似的問題。請在Apple收到您的消息時更新。 –

+0

對此有何更新? – Anastasia

1

遇到同樣的問題,這裏就是我得到了周圍:

放下你的自定義類,並在的UILabel創建類,你的情況的UILabel + ThinText:

- (void) setThinText:(BOOL)thinText 
{ 
    if (thinText) { 
     [self setFont:[UIFont fontWithName:@"Raleway-Light" size:[[self font] pointSize]]]; 
    } 
} 

在你的故事板,選擇您的標籤,選擇身份檢查,並添加以下用戶自定義運行屬性

的keyPath:thinText - 類型:布爾 - :檢查

0

我這個問題了。我解決它在每個ViewController中設置自定義字體。讓我告訴你一個例子:

CustomViewController.h 
@interface CustonViewController 

@property (strong, nonatomic) IBOutlet UILabel* someLabel; 

@end 

CustomViewController.m

- (void)viewDidLoad 
{ 
    [self setUoFonts]; 
} 

- (void)setUpFonts 
{ 
    self.someLabel.font = [UIFont fontWithName:@"AmaticSC-Regular" size:self.someLabel.font.pointSize]; 
} 

這就是它!你將有你的翻譯和你的自定義字體。

記得從StoryBoard中刪除自定義類。

相關問題