[Swift通天遁地]五、高级扩展-(13)图片资源本地化设置:根据不同的语言环境显示不同语言版本图片

★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:山青咏芝(shanqingyongzhi)
➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:https://www.cnblogs.com/strengthen/p/10260296.html 
➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★

目录:[Swift]通天遁地Swift

本文将演示如何给应用程序中的图片资源,进行本地化设置。

在项目文件夹【DemoApp】上点击鼠标右键,弹出右键菜单。

【Add Files to "DemoApp"】-> 导入图片文件 -> 【Add】

当前的图片为中文,为该图片添加本地化设置,

点击显示或隐藏工具面板图标,显示右侧的面板区。

点击【Localize...】本地化按钮,弹出本地化设置窗口。

点击选择【English】->【Localize】给图片添加英语环境的支持。

项目文件名称【DemoApp】->【General】->在项目区域选择项目名称,显示项目的信息设置面板。

点击本地化设置区域【Localizations】下方的【+】按钮,打开语言列表。

->选择简体中文选项【Chinese(simplified)(zh-Hans)】,给项目添加简体中文的支持。

->在弹出的文件选择窗口中,只保留图片文件的选择

->【Finish】完成按钮,给字符串文件添加多语言的支持

点击字符串文件【strengthen.png】左侧的三角箭头,显示字符串文件的各个语言版本。

选择【strengthen.png(English)】,鼠标右键->【Show in Finder】跳转到图片所在的文件夹。

->复制粘贴英文版的图片文件至此处->【替换】

修改应用程序的语言环境:

【Product】->【Scheme】->【Edit Scheme】->【Options】

->【Application Language】:【Chinese(simplified)】->【Close】

在项目导航区,打开视图控制器的代码文件【ViewController.swift】

现在开始编写代码,创建一个图像视图,显示本地化的图片资源。

 1 import UIKit
 2 
 3 class ViewController: UIViewController {
 4 
 5     override func viewDidLoad() {
 6         super.viewDidLoad()
 7         // Do any additional setup after loading the view, typically from a nib.
 8         
 9         //从项目中读取进行本地化处理的图片文件
10         let localizedImage = UIImage(named: "contentMarketing")
11         //创建一个图像视图对象,以显示该图片资源
12         let imageView = UIImageView(image: localizedImage)
13         //设置图像视图对象的显示区域
14         imageView.frame = CGRect(x: 0, y: 40,  320, height: 380)
15         //设置图像视图的图片内容
16         imageView.image = localizedImage
17         
18         //设置根视图的背景颜色
19         self.view.backgroundColor = UIColor(red: 0, green: 154.0/255.0, blue: 154.0/255.0, alpha: 0)
20         //将图像视图添加到根视图
21         self.view.addSubview(imageView)
22     }
23 
24     override func didReceiveMemoryWarning() {
25         super.didReceiveMemoryWarning()
26         // Dispose of any resources that can be recreated.
27     }
28 }
原文地址:https://www.cnblogs.com/strengthen/p/10260296.html