多语言资源文件加载的一种解决方案
IOS上对于字符串,提供能国际化支持,可以用NSLocalizedString来实现国际化,但是对于图片,声音等文件,就需要我们自己来控制了。下面IOS上多种语言资源文件加载的一种解决方案,如果大家有什么更好的想法,欢迎留言告知。
[cpp]
//
//
// ResManager.h
//
// Created by 周海锋 on 12-4-16.
// Copyright (c) 2012年 CJLU. All rights reserved.
//
#import <foundation h="" foundation="">
#import <uikit h="" uikit="">
typedef enum {
Chinese,
English,
Tradition,
}Language;
@interface ResManager : NSObject
{
Language language;
}
@property (nonatomic,assign) Language language;
+(ResManager *)ShareManager;
-(UIImage *) LoadImage:(NSString *) img;
@end
</uikit></foundation>
[cpp]
//
// ResManager.m
//
// Created by 周海锋 on 12-4-16.
// Copyright (c) 2012年 CJLU. All rights reserved.
//
#import "ResManager.h"
@implementation ResManager
@synthesize language;
static ResManager * resManger = nil;
+(ResManager *)ShareManager
{
@synchronized(self) {
if (resManger == nil) {
resManger = [[self alloc] init];
}
}
return resManger;
}
//唯一一次alloc单例,之后均返回nil
+ (id)allocWithZone:(NSZone *)zone
{
@synchronized(self) {
if (resManger == nil) {
resManger = [super allocWithZone:zone];
return resManger;
}
}
return nil;
}
//copy返回单例本身
- (id)copyWithZone:(NSZone *)zone
{
return self;
}
-(id) init
{
if (self = [super init]) {
language = Chinese;
}
return self;
}
-(UIImage *) LoadImage:(NSString *) name
{
switch (language) {
case Chinese:
name = [name stringByAppendingString:@"_c.png"];
break;
case English:
name = [name stringByAppendingString:@"_e.png"];
break;
case Tradition:
name = [name stringByAppendingString:@"_t.png"];
&nbs
相关新闻>>
- 发表评论
-
- 最新评论 更多>>