2011-11-30 31 views
2

親愛的程序員,自定義的UILabel創作,以避免本地化問題

我創建一個customLabel類象下面這樣:

@interface CustomLabel : UILabel { 
    NSString *customBundlePath; 
} 

@implementation CustomLabel 

- (void)drawTextInRect:(CGRect)rect 
{ 
    NSString *result=[self getLocalvalue:self.text]; 
    [result drawInRect:rect withFont:self.font]; 
} 

-(void)awakeFromNib 
{ 
    NSLog(@"%@",self.text); 
} 

-(NSString *)getLocalvalue:(NSString*)textTolocalize 
{ 

    // some code 
    return localizedText; 
} 

但我的問題是,drawTextInRect方法在的時候一個標籤調用一次筆尖加載。

如果視圖再次出現popig,那麼將爲每個customLabel對象執行哪個方法?

請幫我一把。 提前致謝。

+0

只是爲了本地化,你不必創建自定義標籤。 – Satyam

+0

但我在我的應用程序中有這麼多的意見。所以我需要它先生薩蒂揚 –

+0

做ViewWillApper方法 –

回答

1

您不需要自定義類。

NSString *someTextString = NSLocalizedString(@"SomeText", @"Description of text for translators") 
[myLabel setText:someTextString]; 

然後,您可以從文件中提取字符串並提供正確的本地化文本。

一些有用的鏈接:

http://www.icanlocalize.com/site/tutorials/iphone-applications-localization-guide/

http://www.raywenderlich.com/2876/how-to-localize-an-iphone-app-tutorial

+0

我已經這樣做了,但在我的應用程序中,我有近1000多個本地化標籤。我不需要到處寫這麼多的代碼,我需要通過CustomLabel類親愛的Javy引用每個標籤來減少我的代碼冗餘。 –

+0

您打算如何獲取本地化文本字符串? – TigerCoding