zoukankan      html  css  js  c++  java
  • iOS

    前言

    	public class NSLocale : NSObject, NSCopying, NSSecureCoding
    
    • NSLocale 类返回本地化信息,主要体现在"语言"和"区域格式"这两个设置项。

    1、NSLocale 本地化信息的创建

    	// 用标示符创建
    	let locale1:NSLocale = NSLocale(localeIdentifier: "zh_CN")
    	    
    	let strSymbol:AnyObject? = locale1.objectForKey(NSLocaleCurrencySymbol)
    	  	
    	// 返回系统初始本地化信息
    	let locale2:NSLocale = NSLocale.systemLocale()
    	    
    	let calendarIdentifier = locale2.objectForKey(NSLocaleCalendar)?.calendarIdentifier
    	   	
    	// 一直保持在 cache 中,第一次用此方法实例化对象后,即使修改了本地化设定,也不会改变
    	let locale3:NSLocale = NSLocale.currentLocale()
    	    
    	// 每次修改本地化设定,其实例化的对象也会随之改变
    	let locale4:NSLocale = NSLocale.autoupdatingCurrentLocale()
    

    2、NSLocale 本地化信息的设置

    	let calendar:NSCalendar = NSCalendar.currentCalendar()
    		
    	// 设置区域
    	calendar.locale = NSLocale(localeIdentifier: "zh_CN")
    

    3、NSLocale 本地化信息的获取

    	let locale = NSLocale.currentLocale()
    	    
    	// 根据不同的 key 返回各种本地化信息
    	let strSymbol:AnyObject? = locale.objectForKey(NSLocaleCurrencySymbol)
    	    
    	let calendar:AnyObject? = NSLocale.currentLocale().objectForKey(NSLocaleCalendar)
    

    4、显示特定地区代号下相应键的显示名称

    	let locale = NSLocale(localeIdentifier: "zh_CN")
    	    
    	let str = locale.displayNameForKey(NSLocaleIdentifier, value: "en_US")
    
  • 相关阅读:
    gazebo自建小车备忘
    关于hokuyo的一些参数的备忘
    xenserver加入池报错The servers in this pool are not homogeneous
    exchange管理控制台初始化失败--Kerberos连接失败
    修复windows系统更新失败
    powershell同步时间
    powershell创建密文密码文件
    powershell常用命令
    Graylog客户端及服务端
    powershell,cmd,shell查看帮助
  • 原文地址:https://www.cnblogs.com/QianChia/p/5777451.html
Copyright © 2011-2022 走看看