iOS 开发笔记和技巧总结 (五)

来源:互联网 发布:淘宝助理5.5使用教程 编辑:程序博客网 时间:2024/05/20 05:26
如何让你的iPhone程序支持多语言环境(本地化)

我们知道,Cocoa程序是完全支持多语言的,包括iPhone中的程序。这里简单介绍一下制作多语言iPhone程序的方法,同时也是iPhone中显示中文的最好办法。
XCode中支持多语言
在项目中点右键,选择Add->New File
在列表中选择Strings File
可以叫做Localizable.strings,也可以取别的名字,比如MyApp.strings
选中MyApp.string,按command+i,点击左下方的Make File Localizable,你会看到General中的Localizations里面已经有了English。
点击下面的Add Localization,添加一个zh_CN(简体中文)和一个zh_TW 或者 zh_HK(繁体中文)。注意zh_Hans(简体中文)和zh_Hant(繁体中文)在Mac中可以正确识别,但是在iPhone中不能正确识别。
如果你想支持别的语言,可以添加:
日语:Japanese
德语:German
西班牙语:Spanish
法语:French
.strings文件的内容可以是标准的plist格式,也可以是旧的列表格式:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>mykey</key>
<string>myvalue</string>
….
</dict>
</plist>
字符串如果要换行的话,直接按回车换行,不要写成\n这种形式。
或者直接使用旧式的列表格式:
"mykey" = "myvalue";

注意每行后面加分号。
如果你使用的是Localizable.strings,那么你在程序中可以这样获取字符串:
NSLocalizedString(@"mykey", nil)
如果你使用的是自定义名字的.strings,比如MyApp.strings,那么你在程序中可以这样获取字符串:
NSLocalizedStringFromTable (@"mykey",@"MyApp", nil)
这样即可获取到"myvalue"这个字符串,可以是任何语言。
如果你使用的是官方的iPhone SDK,那么项目中包含这个.strings就可以直接使用了,如果你使用的是toolchain,那么需要修改一下Makefile:
增加
LANG_FILES=$(wildcard *.lproj)
LANG_FILES_ABS=$(addprefix $(SRCROOT)/,$(LANG_FILES))
RESOURCES=Resources
找到
$(APP_ABS): $(INFOPLIST_ABS)
在最后一行增加:
cp -R $(LANG_FILES_ABS) $(APP_ABS)/$(RESOURCES)

这样即可让你的iPhone程序支持多语言环境了。 当然如果你不怕麻烦,也可以每次都手工把这些.lproj目录复制到编译好的Bundle里,也是一样的。

获取当前的系统时间 年-月-日  小时-分钟-秒   
控制台NSLOG出的的格式  2011-09-21 07:54:46

代码如下:

NSDate * newDate = [NSDate date];
NSDateFormatter *dateformat=[[NSDateFormatter alloc] init];
[dateformat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSString * newDateOne = [dateformat stringFromDate:newDate];
[dateformat setFormatterBehavior:NSDateFormatterFullStyle];
[dateformat setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];
NSLog(@"%@",newDateOne);

控制Default.png图片的显示时间
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions   
//等待1秒进入首页

  self.timer=[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerFired:) userInfo:nil repeats:NO];

[[NSRunLoop currentRunLoop] addTimer:self.connectionTimer forMode:NSDefaultRunLoopMode];

 do{

    [[NSRunLoop currentRunLoop]runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];

//控制default图片显示的时间
 }while (!done);    

-(void)timerFired:(NSTimer *)timer{

    done=YES;

}

iphone 自定义控件,通讯录,网络,电子书,控件特效 等源码 
part 1--入门:
1. xcode 版本下载 以及 iphone sdk 下载:
最新版本在此下载:
http://developer.apple.com/devcenter/ios/index.action
其他版本请看
http://connect.apple.com/cgi-bin ... 1.0.1.1.0.3.3.3.3.1
2. 入门教程:
http://www.devdiv.com/thread-46499-1-1.html

part 2--代码、例程:
1. iphone编码转换方法:
http://www.devdiv.com/thread-70549-1-1.html

2. 自定义控件总结及常见页面效果:
http://www.devdiv.com/thread-63456-1-1.html

3. 通过custom url scheme启动应用程序:
http://www.devdiv.com/thread-30788-1-2.html

4. 歌曲剪切的代码例子
http://www.devdiv.com/thread-46712-1-1.html

5. ios电子书源码下载
http://www.devdiv.com/thread-65585-1-1.html

6. 条形码识别开源库:
http://www.devdiv.com/thread-41068-1-1.html

7. iPhone 利用CG API画一个饼图(Pie chart) :
http://www.devdiv.com/thread-38136-1-1.html

8. 从图片中的一点取色
http://www.devdiv.com/thread-67521-1-1.html

9. 两种自定义tabbar的方法
http://www.devdiv.com/thread-63143-1-1.html

10. cocos2d帧动画代码共享:
http://www.devdiv.com/thread-69243-1-1.html

11. UILocalNotification实现本地的闹钟提醒的方法
http://www.devdiv.com/thread-69786-1-1.html

12. 导航答的颜色设置
http://www.devdiv.com/thread-69792-1-1.html

13. IOS开发中常量的处理 
http://www.devdiv.com/thread-69949-1-1.html

14. 使用定制的NSDictionary的方法,对NSArray进行排序
http://www.devdiv.com/thread-69948-1-1.html

15. UIImageView实现图片幻灯片
http://www.devdiv.com/thread-69941-1-1.html

16. 短信,电话,邮件,提示框
http://www.devdiv.com/thread-69940-1-1.html

17. 自己写的使用TouchXML解析器的一个小例子,分享一下。
http://www.devdiv.com/thread-69939-1-1.html

18. 网络等待indicator的界面设置 
http://www.devdiv.com/thread-69938-1-1.html

19. 看到一种一套代码,可以多个目标(iPad/iPhone),多个版本(收费版本,试用版本)的方法。 
http://www.devdiv.com/thread-69937-1-1.html

20. 去掉桌面的快捷方式的图标系统自带的高光效果 
http://www.devdiv.com/thread-69936-1-1.html

21. 使用quartz2D绘制阴影的代码
http://www.devdiv.com/thread-70062-1-1.html

22. 分享一个iOS上实现的RSS的例子
http://www.devdiv.com/thread-70071-1-1.html

23. 分享一个别人的柱图
http://www.devdiv.com/thread-70067-1-1.html

24. 判断UITextField的输入只为数字的方法
http://www.devdiv.com/thread-70160-1-1.html

25. UITextField控件处理键盘弹出时遮住输入框的问题
http://www.devdiv.com/thread-70159-1-1.html

26. 分享一个好的文档 Object-C的语法与Cocoa框架-作者李海峰
http://www.devdiv.com/thread-70224-1-1.html

27. iOS 使用定制的NSDictionary的方法,对NSArray进行排序
http://www.devdiv.com/thread-70325-1-1.html

28. iOS录音相关的例子
http://www.devdiv.com/thread-70462-1-1.html

29. 通过代码添加联系人到通讯录的方法
http://www.devdiv.com/thread-70461-1-1.html

30. 中文转拼音
http://www.devdiv.com/thread-70535-1-1.html

31. 分享一个ASIHttpRequest 源码 
http://www.devdiv.com/thread-70536-1-1.html

32. 短信添加联系人+多行textfield效果
http://www.devdiv.com/thread-68572-1-1.html

33. 让模拟器也支持GPS定位(模拟实现)
http://www.devdiv.com/thread-70613-1-1.html

34. 分享别人的两种闹钟的实现方法
http://www.devdiv.com/thread-70616-1-1.html

35. 播放 GIF 图片的代码
http://www.devdiv.com/thread-71496-1-1.html

36. 中文拼音排序的方法和代码例子 
http://www.devdiv.com/thread-71499-1-1.html

37. iPhone 和 iPad 取色程序代码下载
http://www.devdiv.com/thread-71531-1-1.html

38. 官方文档《Xcode单元测试》中文版
http://www.devdiv.com/thread-71713-1-1.html

39. 使用MessageUI发送带附加的邮件
http://www.devdiv.com/thread-71718-1-1.html

40. NSCondition , 多线程同步例子 
http://www.devdiv.com/thread-71719-1-1.html

41. 用cocos2d和chipmunk的DEMO
http://www.devdiv.com/thread-71720-1-1.html

42. Unity开发者杂志下载
http://www.devdiv.com/thread-71721-1-1.html

43.  iPhone按钮特效代码及效果图
http://www.devdiv.com/thread-71723-1-1.html

44. 玻璃破碎的特效,以及实现该特效的代码 
http://www.devdiv.com/thread-71799-1-1.html

45. iPhone上画面切换特效及代码 
http://www.devdiv.com/thread-71943-1-1.html

46. iPhone上的图书翻页特效代码
http://www.devdiv.com/thread-71940-1-1.html

part 3--经验分享:
1. ios4多任务机制:
http://www.devdiv.com/thread-47004-1-1.html

2. iPhone的Push(推送通知)功能原理浅析
http://www.devdiv.com/thread-67433-1-1.html

3. push机制详解:
http://www.devdiv.com/thread-41489-1-1.html

4. push消息的服务器端测试程序
http://www.devdiv.com/thread-69776-1-1.html

5.  push消息的服务端和客户端例子,测试通过的。
http://www.devdiv.com/thread-70070-1-1.html

6. iphone分区与目录结构:
http://www.devdiv.com/thread-31598-1-2.html

7. iPhone 路径大全:
http://www.devdiv.com/thread-31613-1-1.html

8. iPhone用户、用户组、权限解惑:
http://www.devdiv.com/thread-31617-1-1.html

9. ios系统架构:
http://www.devdiv.com/thread-30861-1-2.html

10. 上传一个老外的截屏工具
http://www.devdiv.com/thread-70152-1-1.html


part 4--教程:
1. Obj-C袖珍參考手冊(chm) :
http://www.devdiv.com/thread-30339-1-1.html

2. Xcode_cn开发员入门导引,挺不错的入门资料!
http://www.devdiv.com/thread-49926-1-1.html

3. iPhone开发基础教程(前12章)
http://www.devdiv.com/thread-65932-1-1.html

4. objective-c例程系列:
http://www.devdiv.com/forum.php? ... ypeid&typeid=32

5. 电子书推荐:
http://www.devdiv.com/thread-64361-1-1.html

6. 分享一个UIWebView的使用的文档,希望对大家有用
http://www.devdiv.com/thread-69795-1-1.html

0 0