init
This commit is contained in:
parent
ebe03ffbd4
commit
ee1bc5bc32
@ -0,0 +1,17 @@
|
|||||||
|
//
|
||||||
|
// AppDelegate.h
|
||||||
|
// iOSAppLanguageSwitchDemo
|
||||||
|
//
|
||||||
|
// Created by zengqingfu on 2017/6/13.
|
||||||
|
// Copyright © 2017年 zengqingfu. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
@interface AppDelegate : UIResponder <UIApplicationDelegate>
|
||||||
|
|
||||||
|
@property (strong, nonatomic) UIWindow *window;
|
||||||
|
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
@ -0,0 +1,58 @@
|
|||||||
|
//
|
||||||
|
// AppDelegate.m
|
||||||
|
// iOSAppLanguageSwitchDemo
|
||||||
|
//
|
||||||
|
// Created by zengqingfu on 2017/6/13.
|
||||||
|
// Copyright © 2017年 zengqingfu. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "AppDelegate.h"
|
||||||
|
#import "FirstViewController.h"
|
||||||
|
@interface AppDelegate ()
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation AppDelegate
|
||||||
|
|
||||||
|
|
||||||
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||||
|
|
||||||
|
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||||
|
self.window.backgroundColor = [UIColor whiteColor];
|
||||||
|
[self.window makeKeyAndVisible];
|
||||||
|
|
||||||
|
FirstViewController *vc = [[FirstViewController alloc] init];
|
||||||
|
self.window.rootViewController = vc;
|
||||||
|
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||||
|
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||||
|
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||||
|
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||||
|
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||||
|
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||||
|
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||||
|
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@end
|
@ -0,0 +1,68 @@
|
|||||||
|
{
|
||||||
|
"images" : [
|
||||||
|
{
|
||||||
|
"idiom" : "iphone",
|
||||||
|
"size" : "29x29",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "iphone",
|
||||||
|
"size" : "29x29",
|
||||||
|
"scale" : "3x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "iphone",
|
||||||
|
"size" : "40x40",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "iphone",
|
||||||
|
"size" : "40x40",
|
||||||
|
"scale" : "3x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "iphone",
|
||||||
|
"size" : "60x60",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "iphone",
|
||||||
|
"size" : "60x60",
|
||||||
|
"scale" : "3x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "ipad",
|
||||||
|
"size" : "29x29",
|
||||||
|
"scale" : "1x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "ipad",
|
||||||
|
"size" : "29x29",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "ipad",
|
||||||
|
"size" : "40x40",
|
||||||
|
"scale" : "1x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "ipad",
|
||||||
|
"size" : "40x40",
|
||||||
|
"scale" : "2x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "ipad",
|
||||||
|
"size" : "76x76",
|
||||||
|
"scale" : "1x"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"idiom" : "ipad",
|
||||||
|
"size" : "76x76",
|
||||||
|
"scale" : "2x"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"info" : {
|
||||||
|
"version" : 1,
|
||||||
|
"author" : "xcode"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
<?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="FirstViewController">
|
||||||
|
<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>
|
||||||
|
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="dJk-yb-oRh">
|
||||||
|
<rect key="frame" x="102" y="109" width="46" height="30"/>
|
||||||
|
<state key="normal" title="下一页"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="nextVCAction:" destination="-1" eventType="touchUpInside" id="9dH-0f-sgI"/>
|
||||||
|
</connections>
|
||||||
|
</button>
|
||||||
|
</subviews>
|
||||||
|
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||||
|
<constraints>
|
||||||
|
<constraint firstItem="dJk-yb-oRh" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" constant="109" id="6FY-GY-3Mi"/>
|
||||||
|
<constraint firstItem="dJk-yb-oRh" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="102" id="AdS-f4-g0w"/>
|
||||||
|
</constraints>
|
||||||
|
</view>
|
||||||
|
</objects>
|
||||||
|
</document>
|
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11134" systemVersion="15F34" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
||||||
|
<dependencies>
|
||||||
|
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11106"/>
|
||||||
|
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||||
|
</dependencies>
|
||||||
|
<scenes>
|
||||||
|
<!--View Controller-->
|
||||||
|
<scene sceneID="EHf-IW-A2E">
|
||||||
|
<objects>
|
||||||
|
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||||
|
<layoutGuides>
|
||||||
|
<viewControllerLayoutGuide type="top" id="Llm-lL-Icb"/>
|
||||||
|
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
|
||||||
|
</layoutGuides>
|
||||||
|
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||||
|
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||||
|
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||||
|
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||||
|
</view>
|
||||||
|
</viewController>
|
||||||
|
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||||
|
</objects>
|
||||||
|
<point key="canvasLocation" x="53" y="375"/>
|
||||||
|
</scene>
|
||||||
|
</scenes>
|
||||||
|
</document>
|
@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
Localizable.strings
|
||||||
|
iOSAppLanguageSwitchDemo
|
||||||
|
|
||||||
|
Created by zengqingfu on 2017/6/13.
|
||||||
|
Copyright © 2017年 zengqingfu. All rights reserved.
|
||||||
|
*/
|
||||||
|
"cus_item" = "这是base";
|
@ -0,0 +1,82 @@
|
|||||||
|
<?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="SecondViewController">
|
||||||
|
<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>
|
||||||
|
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="sRN-Uf-gCL">
|
||||||
|
<rect key="frame" x="65" y="123" width="77" height="30"/>
|
||||||
|
<state key="normal" title="设置成中文"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="setupChineseAction:" destination="-1" eventType="touchUpInside" id="mBY-0D-cH6"/>
|
||||||
|
</connections>
|
||||||
|
</button>
|
||||||
|
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="FKp-xO-AWr">
|
||||||
|
<rect key="frame" x="65" y="179" width="77" height="30"/>
|
||||||
|
<state key="normal" title="设置成英文"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="setupEnglishAction:" destination="-1" eventType="touchUpInside" id="Dnz-Rf-lBd"/>
|
||||||
|
</connections>
|
||||||
|
</button>
|
||||||
|
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="wzO-U2-Cbk">
|
||||||
|
<rect key="frame" x="65" y="235" width="138" height="30"/>
|
||||||
|
<state key="normal" title="获取当前自定义语言"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="currentLanguage:" destination="-1" eventType="touchUpInside" id="np0-hM-mXL"/>
|
||||||
|
</connections>
|
||||||
|
</button>
|
||||||
|
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="hqn-O1-exW">
|
||||||
|
<rect key="frame" x="65" y="291" width="108" height="30"/>
|
||||||
|
<state key="normal" title="恢复成系统语言"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="restoreLanguageAction:" destination="-1" eventType="touchUpInside" id="k1k-W5-sKy"/>
|
||||||
|
</connections>
|
||||||
|
</button>
|
||||||
|
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="CK4-kE-Lyr">
|
||||||
|
<rect key="frame" x="16" y="14" width="31" height="30"/>
|
||||||
|
<state key="normal" title="关闭"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="closeAction:" destination="-1" eventType="touchUpInside" id="mjd-C7-jYk"/>
|
||||||
|
</connections>
|
||||||
|
</button>
|
||||||
|
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="kXe-Ad-9Ls">
|
||||||
|
<rect key="frame" x="65" y="347" width="77" height="30"/>
|
||||||
|
<state key="normal" title="字符串测试"/>
|
||||||
|
<connections>
|
||||||
|
<action selector="strTestAction:" destination="-1" eventType="touchUpInside" id="PO5-5G-jhi"/>
|
||||||
|
</connections>
|
||||||
|
</button>
|
||||||
|
</subviews>
|
||||||
|
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||||
|
<constraints>
|
||||||
|
<constraint firstItem="kXe-Ad-9Ls" firstAttribute="top" secondItem="hqn-O1-exW" secondAttribute="bottom" constant="26" id="4YK-gN-T9t"/>
|
||||||
|
<constraint firstItem="CK4-kE-Lyr" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" constant="14" id="4aB-dt-YgH"/>
|
||||||
|
<constraint firstItem="CK4-kE-Lyr" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="16" id="Cfa-qF-YDo"/>
|
||||||
|
<constraint firstItem="wzO-U2-Cbk" firstAttribute="top" secondItem="FKp-xO-AWr" secondAttribute="bottom" constant="26" id="Dh4-bJ-wXO"/>
|
||||||
|
<constraint firstItem="hqn-O1-exW" firstAttribute="leading" secondItem="sRN-Uf-gCL" secondAttribute="leading" id="PO9-cG-Zum"/>
|
||||||
|
<constraint firstItem="sRN-Uf-gCL" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" constant="123" id="R1r-gY-h0T"/>
|
||||||
|
<constraint firstItem="kXe-Ad-9Ls" firstAttribute="leading" secondItem="hqn-O1-exW" secondAttribute="leading" id="RQp-Rz-r7y"/>
|
||||||
|
<constraint firstItem="FKp-xO-AWr" firstAttribute="top" secondItem="sRN-Uf-gCL" secondAttribute="bottom" constant="26" id="XK8-n4-tUK"/>
|
||||||
|
<constraint firstItem="hqn-O1-exW" firstAttribute="top" secondItem="wzO-U2-Cbk" secondAttribute="bottom" constant="26" id="dOU-dj-qqE"/>
|
||||||
|
<constraint firstItem="wzO-U2-Cbk" firstAttribute="leading" secondItem="sRN-Uf-gCL" secondAttribute="leading" id="rNk-Ve-iEb"/>
|
||||||
|
<constraint firstItem="sRN-Uf-gCL" firstAttribute="leading" secondItem="i5M-Pr-FkT" secondAttribute="leading" constant="65" id="xOy-9Z-Q15"/>
|
||||||
|
<constraint firstItem="FKp-xO-AWr" firstAttribute="leading" secondItem="sRN-Uf-gCL" secondAttribute="leading" id="yPv-ji-HkS"/>
|
||||||
|
</constraints>
|
||||||
|
</view>
|
||||||
|
</objects>
|
||||||
|
</document>
|
@ -0,0 +1,35 @@
|
|||||||
|
//
|
||||||
|
// NSBundle+AppLanguageSwitch.h
|
||||||
|
// https://github.com/zengqingf/iOSAppLanguageSwitch
|
||||||
|
//
|
||||||
|
// Created by zengqingfu on 2017/6/13.
|
||||||
|
// Copyright © 2017年 zengqingfu. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
//语言改变通知
|
||||||
|
FOUNDATION_EXPORT NSString * const ZZAppLanguageDidChangeNotification;
|
||||||
|
@interface NSBundle (AppLanguageSwitch)
|
||||||
|
|
||||||
|
/**
|
||||||
|
设置语言
|
||||||
|
|
||||||
|
@param language 参数为语言包的前缀,比如Base.lproj 传入Base、
|
||||||
|
中文语言包zh-Hans.lproj传入zh-Hans,前提是工程中已经提前加入了语言包
|
||||||
|
*/
|
||||||
|
+ (void)setCusLanguage:(NSString *)language;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
获取当前的自定义语言,如果使用的是跟随系统语言出参为nil
|
||||||
|
|
||||||
|
@return 语言类型
|
||||||
|
*/
|
||||||
|
+ (NSString *)getCusLanguage;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
恢复成跟随系统语言
|
||||||
|
*/
|
||||||
|
+ (void)restoreSysLanguage;
|
||||||
|
@end
|
@ -0,0 +1,70 @@
|
|||||||
|
//
|
||||||
|
// NSBundle+AppLanguageSwitch.m
|
||||||
|
// https://github.com/zengqingf/iOSAppLanguageSwitch
|
||||||
|
//
|
||||||
|
// Created by zengqingfu on 2017/6/13.
|
||||||
|
// Copyright © 2017年 zengqingfu. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "NSBundle+AppLanguageSwitch.h"
|
||||||
|
#import <objc/runtime.h>
|
||||||
|
|
||||||
|
|
||||||
|
NSString * const ZZAppLanguageDidChangeNotification = @"cc.devfu.languagedidchange";
|
||||||
|
|
||||||
|
static const char kBundleKey = 0;
|
||||||
|
@interface ZZBundleEx : NSBundle
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation ZZBundleEx
|
||||||
|
|
||||||
|
- (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName {
|
||||||
|
NSBundle *bundle = objc_getAssociatedObject(self, &kBundleKey);
|
||||||
|
if (bundle) {
|
||||||
|
return [bundle localizedStringForKey:key value:value table:tableName];
|
||||||
|
} else {
|
||||||
|
return [super localizedStringForKey:key value:value table:tableName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
static NSString *AppLanguageSwitchKey = @"App_Language_Switch_Key";
|
||||||
|
@implementation NSBundle (AppLanguageSwitch)
|
||||||
|
+ (void)setCusLanguage:(NSString *)language {
|
||||||
|
id value = nil;
|
||||||
|
NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
|
||||||
|
if (language) {
|
||||||
|
value = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:language ofType:@"lproj"]];
|
||||||
|
NSAssert(value != nil, @"value不能为空,请检查参数是否正确");
|
||||||
|
[df setObject:language forKey:AppLanguageSwitchKey];
|
||||||
|
[df synchronize];
|
||||||
|
} else {
|
||||||
|
[df removeObjectForKey:AppLanguageSwitchKey];
|
||||||
|
[df synchronize];
|
||||||
|
}
|
||||||
|
objc_setAssociatedObject([NSBundle mainBundle], &kBundleKey, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
||||||
|
[[NSNotificationCenter defaultCenter] postNotificationName:ZZAppLanguageDidChangeNotification object:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSString *)getCusLanguage {
|
||||||
|
NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
|
||||||
|
NSString *language = [df objectForKey:AppLanguageSwitchKey];
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void)restoreSysLanguage {
|
||||||
|
[self setCusLanguage:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (void)load {
|
||||||
|
static dispatch_once_t onceToken;
|
||||||
|
dispatch_once(&onceToken, ^{
|
||||||
|
object_setClass([NSBundle mainBundle],[ZZBundleEx class]);
|
||||||
|
NSString *language = [self getCusLanguage];
|
||||||
|
if (language) {
|
||||||
|
[self setCusLanguage:language];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
@end
|
@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// FirstViewController.h
|
||||||
|
// iOSAppLanguageSwitchDemo
|
||||||
|
//
|
||||||
|
// Created by zengqingfu on 2017/6/13.
|
||||||
|
// Copyright © 2017年 zengqingfu. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
@interface FirstViewController : UIViewController
|
||||||
|
|
||||||
|
@end
|
@ -0,0 +1,53 @@
|
|||||||
|
//
|
||||||
|
// FirstViewController.m
|
||||||
|
// iOSAppLanguageSwitchDemo
|
||||||
|
//
|
||||||
|
// Created by zengqingfu on 2017/6/13.
|
||||||
|
// Copyright © 2017年 zengqingfu. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "FirstViewController.h"
|
||||||
|
#import "SecondViewController.h"
|
||||||
|
#import "NSBundle+AppLanguageSwitch.h"
|
||||||
|
@interface FirstViewController ()
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation FirstViewController
|
||||||
|
- (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) {
|
||||||
|
self.view = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (IBAction)nextVCAction:(id)sender {
|
||||||
|
SecondViewController *vc = [[SecondViewController alloc] init];
|
||||||
|
[self presentViewController:vc animated:YES 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
|
43
iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/Info.plist
Normal file
43
iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/Info.plist
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
|
<plist version="1.0">
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleDevelopmentRegion</key>
|
||||||
|
<string>en</string>
|
||||||
|
<key>CFBundleExecutable</key>
|
||||||
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
|
<key>CFBundleIdentifier</key>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||||
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
|
<string>6.0</string>
|
||||||
|
<key>CFBundleName</key>
|
||||||
|
<string>$(PRODUCT_NAME)</string>
|
||||||
|
<key>CFBundlePackageType</key>
|
||||||
|
<string>APPL</string>
|
||||||
|
<key>CFBundleShortVersionString</key>
|
||||||
|
<string>1.0</string>
|
||||||
|
<key>CFBundleVersion</key>
|
||||||
|
<string>1</string>
|
||||||
|
<key>LSRequiresIPhoneOS</key>
|
||||||
|
<true/>
|
||||||
|
<key>UILaunchStoryboardName</key>
|
||||||
|
<string>LaunchScreen</string>
|
||||||
|
<key>UIRequiredDeviceCapabilities</key>
|
||||||
|
<array>
|
||||||
|
<string>armv7</string>
|
||||||
|
</array>
|
||||||
|
<key>UISupportedInterfaceOrientations</key>
|
||||||
|
<array>
|
||||||
|
<string>UIInterfaceOrientationPortrait</string>
|
||||||
|
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||||
|
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||||
|
</array>
|
||||||
|
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||||
|
<array>
|
||||||
|
<string>UIInterfaceOrientationPortrait</string>
|
||||||
|
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||||
|
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||||
|
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</plist>
|
@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// SecondViewController.h
|
||||||
|
// iOSAppLanguageSwitchDemo
|
||||||
|
//
|
||||||
|
// Created by zengqingfu on 2017/6/13.
|
||||||
|
// Copyright © 2017年 zengqingfu. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
|
||||||
|
@interface SecondViewController : UIViewController
|
||||||
|
|
||||||
|
@end
|
@ -0,0 +1,60 @@
|
|||||||
|
//
|
||||||
|
// SecondViewController.m
|
||||||
|
// iOSAppLanguageSwitchDemo
|
||||||
|
//
|
||||||
|
// Created by zengqingfu on 2017/6/13.
|
||||||
|
// Copyright © 2017年 zengqingfu. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "SecondViewController.h"
|
||||||
|
#import "NSBundle+AppLanguageSwitch.h"
|
||||||
|
@interface SecondViewController ()
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation SecondViewController
|
||||||
|
|
||||||
|
- (void)viewDidLoad {
|
||||||
|
[super viewDidLoad];
|
||||||
|
// Do any additional setup after loading the view from its nib.
|
||||||
|
}
|
||||||
|
- (IBAction)closeAction:(id)sender {
|
||||||
|
[self dismissViewControllerAnimated:YES completion:nil];
|
||||||
|
}
|
||||||
|
- (IBAction)setupChineseAction:(id)sender {
|
||||||
|
[NSBundle setCusLanguage:@"zh-Hans"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction)setupEnglishAction:(id)sender {
|
||||||
|
[NSBundle setCusLanguage:@"en"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction)currentLanguage:(id)sender {
|
||||||
|
NSString *currLanguage = [NSBundle getCusLanguage];
|
||||||
|
NSLog(@"当前语言是=%@", currLanguage);
|
||||||
|
}
|
||||||
|
- (IBAction)restoreLanguageAction:(id)sender {
|
||||||
|
[NSBundle restoreSysLanguage];
|
||||||
|
}
|
||||||
|
- (IBAction)strTestAction:(id)sender {
|
||||||
|
|
||||||
|
NSString *tes = NSLocalizedString(@"cus_item", nil);
|
||||||
|
NSLog(@"测试字符的结果是=%@", tes);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (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
|
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
/* Class = "UIButton"; normalTitle = "下一页"; ObjectID = "dJk-yb-oRh"; */
|
||||||
|
"dJk-yb-oRh.normalTitle" = "Next";
|
@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
Localizable.strings
|
||||||
|
iOSAppLanguageSwitchDemo
|
||||||
|
|
||||||
|
Created by zengqingfu on 2017/6/13.
|
||||||
|
Copyright © 2017年 zengqingfu. All rights reserved.
|
||||||
|
*/
|
||||||
|
"cus_item" = "This is English";
|
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
/* Class = "UIButton"; normalTitle = "关闭"; ObjectID = "CK4-kE-Lyr"; */
|
||||||
|
"CK4-kE-Lyr.normalTitle" = "Close";
|
||||||
|
|
||||||
|
/* Class = "UIButton"; normalTitle = "设置成英文"; ObjectID = "FKp-xO-AWr"; */
|
||||||
|
"FKp-xO-AWr.normalTitle" = "Use English";
|
||||||
|
|
||||||
|
/* Class = "UIButton"; normalTitle = "恢复系统语言"; ObjectID = "hqn-O1-exW"; */
|
||||||
|
"hqn-O1-exW.normalTitle" = "Restore To System Language";
|
||||||
|
|
||||||
|
/* Class = "UIButton"; normalTitle = "设置成中文"; ObjectID = "sRN-Uf-gCL"; */
|
||||||
|
"sRN-Uf-gCL.normalTitle" = "Use Chinese";
|
||||||
|
|
||||||
|
/* Class = "UIButton"; normalTitle = "获取当前自定义语言"; ObjectID = "wzO-U2-Cbk"; */
|
||||||
|
"wzO-U2-Cbk.normalTitle" = "get Current Language";
|
||||||
|
|
||||||
|
/* Class = "UIButton"; normalTitle = "字符串测试"; ObjectID = "kXe-Ad-9Ls"; */
|
||||||
|
"kXe-Ad-9Ls.normalTitle" = "String Test";
|
16
iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/main.m
Normal file
16
iOSAppLanguageSwitchDemo/iOSAppLanguageSwitchDemo/main.m
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//
|
||||||
|
// main.m
|
||||||
|
// iOSAppLanguageSwitchDemo
|
||||||
|
//
|
||||||
|
// Created by zengqingfu on 2017/6/13.
|
||||||
|
// Copyright © 2017年 zengqingfu. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import "AppDelegate.h"
|
||||||
|
|
||||||
|
int main(int argc, char * argv[]) {
|
||||||
|
@autoreleasepool {
|
||||||
|
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
|
||||||
|
/* Class = "UIButton"; normalTitle = "下一页"; ObjectID = "dJk-yb-oRh"; */
|
||||||
|
"dJk-yb-oRh.normalTitle" = "下一页";
|
@ -0,0 +1 @@
|
|||||||
|
|
@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
Localizable.strings
|
||||||
|
iOSAppLanguageSwitchDemo
|
||||||
|
|
||||||
|
Created by zengqingfu on 2017/6/13.
|
||||||
|
Copyright © 2017年 zengqingfu. All rights reserved.
|
||||||
|
*/
|
||||||
|
"cus_item" = "这是中文";
|
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
/* Class = "UIButton"; normalTitle = "关闭"; ObjectID = "CK4-kE-Lyr"; */
|
||||||
|
"CK4-kE-Lyr.normalTitle" = "关闭";
|
||||||
|
|
||||||
|
/* Class = "UIButton"; normalTitle = "设置成英文"; ObjectID = "FKp-xO-AWr"; */
|
||||||
|
"FKp-xO-AWr.normalTitle" = "设置成英文";
|
||||||
|
|
||||||
|
/* Class = "UIButton"; normalTitle = "恢复系统语言"; ObjectID = "hqn-O1-exW"; */
|
||||||
|
"hqn-O1-exW.normalTitle" = "恢复系统语言";
|
||||||
|
|
||||||
|
/* Class = "UIButton"; normalTitle = "字符串测试"; ObjectID = "kXe-Ad-9Ls"; */
|
||||||
|
"kXe-Ad-9Ls.normalTitle" = "字符串测试";
|
||||||
|
|
||||||
|
/* Class = "UIButton"; normalTitle = "设置成中文"; ObjectID = "sRN-Uf-gCL"; */
|
||||||
|
"sRN-Uf-gCL.normalTitle" = "设置成中文";
|
||||||
|
|
||||||
|
/* Class = "UIButton"; normalTitle = "获取当前自定义语言"; ObjectID = "wzO-U2-Cbk"; */
|
||||||
|
"wzO-U2-Cbk.normalTitle" = "获取当前自定义语言";
|
Loading…
Reference in New Issue
Block a user