2011-11-30 23 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