This commit is contained in:
小飞侠u 2017-06-13 20:01:17 +08:00
parent 6356945219
commit a2e0c8a9dc
12 changed files with 216 additions and 5 deletions

View File

@ -17,6 +17,9 @@
4B32F1D11EEFE8A40066445B /* FirstViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B32F1D31EEFE8A40066445B /* FirstViewController.xib */; };
4B32F1D81EEFE9850066445B /* SecondViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B32F1DA1EEFE9850066445B /* SecondViewController.xib */; };
4B32F1E71EEFF38C0066445B /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4B32F1E91EEFF38C0066445B /* Localizable.strings */; };
4B32F1FA1EF000220066445B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4B32F1FC1EF000220066445B /* InfoPlist.strings */; };
4B32F2021EF002D90066445B /* ThirdViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B32F2001EF002D90066445B /* ThirdViewController.m */; };
4B32F2041EF003E40066445B /* ThirdViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4B32F2061EF003E40066445B /* ThirdViewController.xib */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@ -43,6 +46,14 @@
4B32F1EB1EEFF38D0066445B /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/Localizable.strings"; sourceTree = "<group>"; };
4B32F1F51EEFF4340066445B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/SecondViewController.strings; sourceTree = "<group>"; };
4B32F1F71EEFF4360066445B /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/SecondViewController.strings"; sourceTree = "<group>"; };
4B32F1FB1EF000220066445B /* Base */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = Base; path = Base.lproj/InfoPlist.strings; sourceTree = "<group>"; };
4B32F1FD1EF000240066445B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
4B32F1FE1EF000250066445B /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
4B32F1FF1EF002D90066445B /* ThirdViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThirdViewController.h; sourceTree = "<group>"; };
4B32F2001EF002D90066445B /* ThirdViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThirdViewController.m; sourceTree = "<group>"; };
4B32F2051EF003E40066445B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/ThirdViewController.xib; sourceTree = "<group>"; };
4B32F2081EF003E50066445B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/ThirdViewController.strings; sourceTree = "<group>"; };
4B32F20A1EF003E60066445B /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/ThirdViewController.strings"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -83,6 +94,9 @@
4B32F1CC1EEFE7D90066445B /* SecondViewController.h */,
4B32F1CD1EEFE7D90066445B /* SecondViewController.m */,
4B32F1DA1EEFE9850066445B /* SecondViewController.xib */,
4B32F1FF1EF002D90066445B /* ThirdViewController.h */,
4B32F2001EF002D90066445B /* ThirdViewController.m */,
4B32F2061EF003E40066445B /* ThirdViewController.xib */,
4B32F1C21EEFDEBE0066445B /* Class */,
4B32F1B71EEFDE840066445B /* Assets.xcassets */,
4B32F1B91EEFDE840066445B /* LaunchScreen.storyboard */,
@ -97,6 +111,7 @@
children = (
4B32F1AC1EEFDE840066445B /* main.m */,
4B32F1E91EEFF38C0066445B /* Localizable.strings */,
4B32F1FC1EF000220066445B /* InfoPlist.strings */,
);
name = "Supporting Files";
sourceTree = "<group>";
@ -141,6 +156,7 @@
TargetAttributes = {
4B32F1A71EEFDE840066445B = {
CreatedOnToolsVersion = 8.3.1;
DevelopmentTeam = YP3GK894M5;
ProvisioningStyle = Automatic;
};
};
@ -169,7 +185,9 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
4B32F2041EF003E40066445B /* ThirdViewController.xib in Resources */,
4B32F1E71EEFF38C0066445B /* Localizable.strings in Resources */,
4B32F1FA1EF000220066445B /* InfoPlist.strings in Resources */,
4B32F1D81EEFE9850066445B /* SecondViewController.xib in Resources */,
4B32F1BB1EEFDE840066445B /* LaunchScreen.storyboard in Resources */,
4B32F1D11EEFE8A40066445B /* FirstViewController.xib in Resources */,
@ -186,6 +204,7 @@
files = (
4B32F1CF1EEFE7DA0066445B /* SecondViewController.m in Sources */,
4B32F1C51EEFDEF40066445B /* NSBundle+AppLanguageSwitch.m in Sources */,
4B32F2021EF002D90066445B /* ThirdViewController.m in Sources */,
4B32F1B01EEFDE840066445B /* AppDelegate.m in Sources */,
4B32F1AD1EEFDE840066445B /* main.m in Sources */,
4B32F1CA1EEFE7C10066445B /* FirstViewController.m in Sources */,
@ -234,6 +253,26 @@
name = Localizable.strings;
sourceTree = "<group>";
};
4B32F1FC1EF000220066445B /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
4B32F1FB1EF000220066445B /* Base */,
4B32F1FD1EF000240066445B /* en */,
4B32F1FE1EF000250066445B /* zh-Hans */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
4B32F2061EF003E40066445B /* ThirdViewController.xib */ = {
isa = PBXVariantGroup;
children = (
4B32F2051EF003E40066445B /* Base */,
4B32F2081EF003E50066445B /* en */,
4B32F20A1EF003E60066445B /* zh-Hans */,
);
name = ThirdViewController.xib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
@ -335,6 +374,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = YP3GK894M5;
INFOPLIST_FILE = iOSAppLanguageSwitchDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
@ -347,6 +387,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = YP3GK894M5;
INFOPLIST_FILE = iOSAppLanguageSwitchDemo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";

View File

@ -0,0 +1,8 @@
/*
InfoPlist.strings
iOSAppLanguageSwitchDemo
Created by zengqingfu on 2017/6/13.
Copyright © 2017年 zengqingfu. All rights reserved.
*/
"CFBundleDisplayName" = "语言切换";

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12118" systemVersion="16F73" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="ThirdViewController">
<connections>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections>
</placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="D8C-Qs-dW6">
<rect key="frame" x="78.5" y="272" width="218" height="123"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="正在设置语言..." textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="yTu-Le-1xE">
<rect key="frame" x="50" y="82" width="118" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" animating="YES" style="whiteLarge" translatesAutoresizingMaskIntoConstraints="NO" id="sQG-5r-3Aq">
<rect key="frame" x="90.5" y="30" width="37" height="37"/>
<color key="color" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
</activityIndicatorView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="yTu-Le-1xE" firstAttribute="leading" secondItem="D8C-Qs-dW6" secondAttribute="leading" constant="50" id="K3w-Ia-vg0"/>
<constraint firstAttribute="bottom" secondItem="yTu-Le-1xE" secondAttribute="bottom" constant="20" id="R70-14-z38"/>
<constraint firstItem="sQG-5r-3Aq" firstAttribute="centerX" secondItem="D8C-Qs-dW6" secondAttribute="centerX" id="aMc-LK-FOm"/>
<constraint firstAttribute="trailing" secondItem="yTu-Le-1xE" secondAttribute="trailing" constant="50" id="fYZ-Cs-e6O"/>
<constraint firstItem="sQG-5r-3Aq" firstAttribute="top" secondItem="D8C-Qs-dW6" secondAttribute="top" constant="30" id="tyN-FA-bK1"/>
<constraint firstItem="yTu-Le-1xE" firstAttribute="top" secondItem="sQG-5r-3Aq" secondAttribute="bottom" constant="15" id="xRf-sN-Qrb"/>
</constraints>
</view>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
<constraint firstItem="D8C-Qs-dW6" firstAttribute="centerX" secondItem="i5M-Pr-FkT" secondAttribute="centerX" id="0nN-dg-VSk"/>
<constraint firstItem="D8C-Qs-dW6" firstAttribute="centerY" secondItem="i5M-Pr-FkT" secondAttribute="centerY" id="9wL-xZ-9Oz"/>
</constraints>
</view>
</objects>
</document>

View File

@ -9,6 +9,8 @@
#import <Foundation/Foundation.h>
//语言改变通知
FOUNDATION_EXPORT NSString * const ZZAppLanguageDidChangeNotification;
@interface NSBundle (AppLanguageSwitch)
/**

View File

@ -8,25 +8,43 @@
#import "SecondViewController.h"
#import "NSBundle+AppLanguageSwitch.h"
#import "ThirdViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(languageChange:) name:ZZAppLanguageDidChangeNotification object:nil];
}
- (void)languageChange:(id)sender {
if (self.isViewLoaded && !self.view.window) {
//nilviewDidLoad
self.view = nil;
}
}
- (IBAction)closeAction:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)setupChineseAction:(id)sender {
[self showHUDCompletion:^{
[NSBundle setCusLanguage:@"zh-Hans"];
}];
}
- (IBAction)setupEnglishAction:(id)sender {
[self showHUDCompletion:^{
[NSBundle setCusLanguage:@"en"];
}];
}
- (IBAction)currentLanguage:(id)sender {
@ -34,7 +52,11 @@
NSLog(@"当前语言是=%@", currLanguage);
}
- (IBAction)restoreLanguageAction:(id)sender {
[self showHUDCompletion:^{
[NSBundle restoreSysLanguage];
}];
}
- (IBAction)strTestAction:(id)sender {
@ -42,6 +64,11 @@
NSLog(@"测试字符的结果是=%@", tes);
}
- (void)showHUDCompletion:(void (^ __nullable)(void))completion {
ThirdViewController *vc = [[ThirdViewController alloc] init];
[self presentViewController:vc animated:NO completion:completion];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.

View File

@ -0,0 +1,13 @@
//
// ThirdViewController.h
// iOSAppLanguageSwitchDemo
//
// Created by zengqingfu on 2017/6/13.
// Copyright © 2017年 zengqingfu. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ThirdViewController : UIViewController
@end

View File

@ -0,0 +1,44 @@
//
// ThirdViewController.m
// iOSAppLanguageSwitchDemo
//
// Created by zengqingfu on 2017/6/13.
// Copyright © 2017 zengqingfu. All rights reserved.
//
#import "ThirdViewController.h"
@interface ThirdViewController ()
@end
@implementation ThirdViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:NO completion:nil];
});
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end

View File

@ -0,0 +1,8 @@
/*
InfoPlist.strings
iOSAppLanguageSwitchDemo
Created by zengqingfu on 2017/6/13.
Copyright © 2017年 zengqingfu. All rights reserved.
*/
"CFBundleDisplayName" = "Lan Switch";

View File

@ -0,0 +1,3 @@
/* Class = "UILabel"; text = "正在设置语言..."; ObjectID = "yTu-Le-1xE"; */
"yTu-Le-1xE.text" = "setting Language";

View File

@ -0,0 +1,8 @@
/*
InfoPlist.strings
iOSAppLanguageSwitchDemo
Created by zengqingfu on 2017/6/13.
Copyright © 2017年 zengqingfu. All rights reserved.
*/
"CFBundleDisplayName" = "语言切换";

View File

@ -0,0 +1,3 @@
/* Class = "UILabel"; text = "正在设置语言..."; ObjectID = "yTu-Le-1xE"; */
"yTu-Le-1xE.text" = "正在设置语言...";