|
25 | 25 | ## 示例
|
26 | 26 |
|
27 | 27 |
|
28 |
| -### SwiftTheme(索引) |
| 28 | +### 索引 |
29 | 29 |
|
30 | 30 | 让UIView 随主题变换背景色?
|
31 | 31 |
|
@@ -53,42 +53,30 @@ imageView.theme_image = ThemeImagePicker(names: "day", "night")
|
53 | 53 | ThemeManager.setTheme(isNight ? 1 : 0)
|
54 | 54 | ```
|
55 | 55 |
|
56 |
| -> 直接根据索引切换样式,便于快速开发,适合主题不多、无需下载主题的App。 |
| 56 | +> 直接根据索引切换主题,便于快速开发。适合主题不多、无需下载主题的App。 |
57 | 57 |
|
58 | 58 |
|
59 |
| -### SwiftTheme(plist) |
| 59 | +### plist |
| 60 | +为了满足通过网络下载和安装主题包的需求,我们支持以plist 配置主题。简单讲就是在plist 中记录配置参数,比如背景色、切图文件名等,在代码中通过key 来指定相应的参数。因此,该plist 文件以及用到的资源文件就组成了一个主题包。 |
60 | 61 |
|
61 |
| -```swift |
| 62 | +以下为用法示例: |
| 63 | + |
| 64 | +``` |
| 65 | +view.theme_backgroundColor = ThemeColorPicker(keyPath: "Global.bg") |
| 66 | +label.theme_textColor = ThemeColorPicker(keyPath: "ViewController.labelText") |
| 67 | +button.theme_setTitleColor(ThemeColorPicker(keyPath: "ViewController.buttonNormal"), forState: .Normal) |
| 68 | +imageView.theme_image = ThemeImagePicker(keyPath: "ViewController.image") |
| 69 | +``` |
| 70 | +> 与索引方式类似,只是具体的参数值变为了间接的key 名称,正因如此赋予了它扩展的能力。 |
62 | 71 |
|
63 |
| -var isNight: Bool = false |
64 |
| - |
65 |
| -class ViewController: UIViewController { |
66 |
| - |
67 |
| - @IBOutlet weak var label : UILabel |
68 |
| - @IBOutlet weak var button : UIButton |
69 |
| - @IBOutlet weak var imageView : UIImageView |
70 |
| - |
71 |
| - override fund viewDidLoad() { |
72 |
| - super.viewDidLoad() |
73 |
| - setupUI() |
74 |
| - } |
75 |
| - |
76 |
| - func setupUI() { |
77 |
| - view.theme_backgroundColor = ThemeColorPicker(keyPath: "Global.bg") |
78 |
| - label.theme_textColor = ThemeColorPicker(keyPath: "ViewController.labelText") |
79 |
| - button.theme_setTitleColor(ThemeColorPicker(keyPath: "ViewController.buttonNormal"), forState: .Normal) |
80 |
| - imageView.theme_image = ThemeImagePicker(keyPath: "ViewController.image") |
81 |
| - } |
82 |
| - |
83 |
| - @IBAction func toggleNight() { |
84 |
| - isNight = !isNight |
85 |
| - ThemeManager.setTheme(isNight ? "Night" : "Day", path: .MainBundle) |
86 |
| - } |
87 |
| - |
88 |
| -} |
| 72 | + |
| 73 | +切换主题时参数为plist 名称,这里以bundle 中的plist 文件及资源文件为例,使用沙箱中的文件也是可以的。 |
| 74 | + |
| 75 | +``` |
| 76 | +ThemeManager.setTheme(isNight ? "Night" : "Day", path: .MainBundle) |
89 | 77 | ```
|
90 | 78 |
|
91 |
| -> 增加主题无需修改代码,适合多主题、包含下载主题的App。 |
| 79 | +> plist 方式增加主题无需修改代码,可以无限扩展主题,因此你完全可以通过这种方式为你的用户开发下载安装主题的功能。 |
92 | 80 |
|
93 | 81 |
|
94 | 82 | ### 主要特点
|
|
0 commit comments