PowenKo, iOS Tutorial , Multi-Languages

September 23, 2011   ·   0 Comments

說明:依系統設定的語言自動切換適合的顯示字串

操作:

在Interface Builder設計時的介面

若系統設定為English則顯示英文介面

若系統設定為繁體中文則顯示為中文介面

如何建立自定的語系檔:
1.在Resources分類下新增檔案 [右鍵/Add/New File…]
2.在範本的分類選擇Other後再選擇 Strings File

3.將存檔檔名設定為 Localizable.strings

4.在 Localizable.strings 檔案上按右鍵並選擇 Get Info

5.選擇左下方的 Make File Localizable

6.將分頁標籤切換至General

7.選擇左下方的 Add Localization

8.輸入新的語系名稱 zh_TW 後按 Add

9.您會看到目前您設定了English及zh_TW兩種語系

10.在檔案清單中您將看到 Localizable Strings (English) 及 Localizable String (zh_TW)

11.開啟後編輯語言字串就可以囉,範例如下:
Localizable.strings (English)

Localizable.strings (zh_TW)

“DemoTitle”=”這是繁體中文的版本”;

“String1″=”蘋果”;

“String2″=”香蕉”;

“String3″=”橘子”;

 

程式碼:
MultiLanguageDemoViewController.h

#import <UIKit/UIKit.h>
@interface MultiLanguageDemoViewController : UIViewController {
IBOutlet UILabel *lbldemotitle;
IBOutlet UILabel *lblstr1;
IBOutlet UILabel *lblstr2;

  1. }
  2. @property (nonatomic,retain) UILabel *lbldemotitle;
  3. @property (nonatomic,retain) UILabel *lblstr1;
  4. @property (nonatomic,retain) UILabel *lblstr2;
  5. @property (nonatomic,retain) UILabel *lblstr3;
  6. @property (nonatomic,retain) UILabel *lblstr4;
  7. @property (nonatomic,retain) UILabel *lblstr5;
  8. @end

複製代碼

MultiLanguageDemoViewController.m

  1. #import “MultiLanguageDemoViewController.h”
  2. @implementation MultiLanguageDemoViewController
  3. @synthesize lbldemotitle,lblstr1,lblstr2,lblstr3,lblstr4,lblstr5;
  4. - (void)viewDidLoad {
  5.     [super viewDidLoad];
  6.         //系統設定取得適合的多國語言字串
  7.         lbldemotitle.text=NSLocalizedString(@”DemoTitle”,nil);
  8.         lblstr1.text= NSLocalizedString(@”String1″,nil);
  9.         lblstr2.text=NSLocalizedString(@”String2″,nil);
  10.         lblstr3.text=NSLocalizedString(@”String3″,nil);
  11.         lblstr4.text=NSLocalizedString(@”String4″,nil);
  12.         lblstr5.text=NSLocalizedString(@”String5″,nil);
  13. }

http://www.cocoachina.com/index.php/archives/cocoachina_161.html

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
iOS Tutorial9

Amazon

adsbygoogle

Recent Posts

Categories

Amazon