本文主要是介绍[Swift 开发] iOS换肤框架 SwiftTheme,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
SwiftTheme是目前iOS平台上最方便的换肤框架,而且功能丰富、高性能、可扩展,提供一个全新的换肤解决方案,使用纯Swift编写,但完全兼容OC。
框架网上可以搜到,咱们今天主要讲一下用法.
1.先定义一些主题颜色
let globalBackgroundColorPicker = ThemeColorPicker(colors: "#EB4F38", "#F4C600", "#56ABE4", "#ECF0F1")
//在MyThemes中设置主题
case Red = 0
case Yello = 1
case Blue = 2
case Night = 3
2.把需要换肤的控件都加进来
//UIButton
btn.theme_backgroundColor = globalBackgroundColorPicker
btn.theme_setTitleColor(ThemeColorPicker(colors: "#000", "#FFF"), forState: .Normal)
<pre name="code" class="objc">//UILabel
label.theme_textColor = globalBackgroundColorPicker
//UINavigationBar
navigationBar.theme_tintColor = globalBarTintColorPicker
navigationBar.theme_barTintColor = globalBarTintColorPicker
//UIImage
nightIcon.theme_image = ThemeImagePicker(names: "icon_night_dark", "icon_night_dark", "icon_night_dark", "icon_night_light")
3.换肤
//循环换肤
MyThemes.switchToNext()//切换到哪个主题
MyThemes.switchTo(MyThemes.Blue)//夜晚模式
MyThemes.switchToNight(true)
plist 方式
以下为用法示例:view.theme_backgroundColor = ThemeColorPicker(keyPath: "Global.backgroundColor")
imageView.theme_image = ThemeImagePicker(keyPath: "SelectedThemeCell.iconImage")
上面用到的
plist
、
image
展示如下:
这篇关于[Swift 开发] iOS换肤框架 SwiftTheme的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!