a simple way to manage theme , a Powerful color/theme/skin manager 中文文档
Color is the foundation of an app presentation, and every mature app should have its own design style.This Project manage colors by enumeration. Each enumeration has a color array corresponding to a different theme. You can edit TCColorConfig.swift to edit or set the default color scheme. You can also set the color scheme dynamically using ThemeManager.sharedManager.setThemeColorList
.
Note that TCColorName
, kDefaultColorList
, ThemeType
need one-to-one correspondence.
// default work with kDefaultColorList
public enum TCColorName:Int {
case ColorNameRed = 0
case ColorNameBlue
}
let kDefaultColorList:[[String]] = [
[ "ee1a1a", "892323"],
[ "1b88ee", "144e84"]
]
public enum ThemeType:Int {
case themeDay = 0
case themeNight
}
A unified color management platform ColorBoardis shown below
Provides a hexadecimal way to set the color based on enum TCColorName
tc_themeBlock
is a block of theme switches that handles not only color changes, but also all UIView-related properties.tc_backgroundColor
: When the theme switch, can be used to set the background color UIViewtc_borderColor
installation layerborderColor
tc_textColor
: set theUILabel
font colortc_highlightedTextColor
: set UILabel highlight font color
UIImageView
requires a different picture in the theme switch, so you need to take a certain norm on the picture naming.
call the function
ThemeManager.sharedManager.setThemeImagePrefix
to normalize the theme image name.
e.g: [" "," night "], then the image named" themeImage " ,The corresponding theme image name is "night_themeImage". There are two ways to set the theme image as below
tc_imageName
:Set the default theme of the picture name
For solid images also provide a way to color the image
func set_imageName(_ imageName:String?,nightTintColor tintColor:TCColorName?)
UIButton
has multiple states for pictures
func tc_setImage(_ imageName: String?, for state: UIControlState)
func tc_setImage(_ imageName: String?, tintColor:TCColorName?,for state: UIControlState)
Available for the font color of UIButton
func tc_setTitleColor(_ color: TCColorName?, for state: UIControlState)
func tc_setTitleShadowColor(_ color: TCColorName?, for state: UIControlState)
Copy all the files in "ThemeColor" folder into your project
config the TCColorConfig.swift
file , you can also use the ColorBoard to manage the color and generate the code
MIT License
Copyright (c) 2018 kyleruan
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.