可以使用继承或者类别来重载方法来进行实时刷新,在一些标签需要进行静态语言切换的时候可以用这个方法
这里使用类别方法来处理
//send the sigle
[[NSNotificationCenter defaultCenter] postNotificationName:@"LangeuageChange" object:[[NSString stringWithFormat:@"%d", iLangCode] retain]];
@interface UILabel(LanguageDeal)
- (void) setLangText:(NSString *)intext;
- (void) reSetText:(NSNotification *)notify;
@end
@implementation UILabel (LanguageDeal)
- (void) setLangText:(NSString *)intext
{
self.text = intext;
//wait for the signal
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reSetText:) name:@"LangeuageChange" object:nil];
}
- (void) reSetText:(NSNotification *)notify
{
NSString * szcode = (NSString *)[notify object];
int code = [szcode intValue];
NSLog(@"reset get %d", code);
if (code == 0)
{
self.text = @"000";
}
else
{
self.text = @"111";
}
}
@end
本文介绍如何通过类别方法实现标签实时刷新,并在不同语言环境下动态调整UI元素显示内容,具体展示了如何利用NSNotification发布通知,触发相应方法更新文本。
5734

被折叠的 条评论
为什么被折叠?



