【问题标题】:Custom UILabel creation to avoid localization problems自定义 UILabel 创建以避免本地化问题
【发布时间】:2011-11-30 12:06:05
【问题描述】:

亲爱的程序员,

我正在创建一个如下所示的 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;
}

但我的问题是,在 nib 加载时,drawTextInRect 方法只为 Label 调用一次。

如果视图再次被popig显示,那么每个customLabel对象会执行哪个方法?

请帮帮我。 提前谢谢。

【问题讨论】:

  • 只是为了本地化,你没有创建自定义标签。
  • 但是我的应用程序中有很多视图。所以我需要它 Satyam 先生
  • 在 ViewWillApper 方法中进行
  • 在 UILabel 类中,ViewWillApper 方法不可用。不是吗?

标签: iphone uilabel awakefromnib


【解决方案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

【讨论】:

  • 我已经通过这种方式完成了,但是在我的应用程序中,我有近 1000 个用于本地化的标签。我不需要到处写这么多代码,我需要通过 CustomLabel 类亲爱的 Javy 引用每个标签来减少我的代码冗余。
  • 您打算如何获取本地化的文本字符串?
猜你喜欢
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-11
  • 2021-08-02
  • 2012-04-13
  • 2019-08-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多