Skip to content

Commit 285faae

Browse files
committed
update readme
1 parent 0307a4e commit 285faae

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

README.md

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
## 示例
2626

2727

28-
### SwiftTheme(索引)
28+
### 索引
2929

3030
让UIView 随主题变换背景色?
3131

@@ -53,42 +53,30 @@ imageView.theme_image = ThemeImagePicker(names: "day", "night")
5353
ThemeManager.setTheme(isNight ? 1 : 0)
5454
```
5555

56-
> 直接根据索引切换样式,便于快速开发适合主题不多、无需下载主题的App。
56+
> 直接根据索引切换主题,便于快速开发适合主题不多、无需下载主题的App。
5757
5858

59-
### SwiftTheme(plist)
59+
### plist
60+
为了满足通过网络下载和安装主题包的需求,我们支持以plist 配置主题。简单讲就是在plist 中记录配置参数,比如背景色、切图文件名等,在代码中通过key 来指定相应的参数。因此,该plist 文件以及用到的资源文件就组成了一个主题包。
6061

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 名称,正因如此赋予了它扩展的能力。
6271
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)
8977
```
9078

91-
> 增加主题无需修改代码,适合多主题、包含下载主题的App
79+
> plist 方式增加主题无需修改代码,可以无限扩展主题,因此你完全可以通过这种方式为你的用户开发下载安装主题的功能
9280
9381

9482
### 主要特点

0 commit comments

Comments
 (0)