[Swift 开发] iOS换肤框架 SwiftTheme

前端之家收集整理的这篇文章主要介绍了[Swift 开发] iOS换肤框架 SwiftTheme前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


SwiftTheme是目前iOS平台上最方便的换肤框架,而且功能丰富、高性能、可扩展,提供一个全新的换肤解决方案,使用纯Swift编写,但完全兼容OC。@H_403_5@


框架网上可以搜到,咱们今天主要讲一下用法.

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_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")

上面用到的 plistimage展示如下: 原文链接:https://www.f2er.com/swift/323401.html

猜你在找的Swift相关文章