Latest 1.0.0
Homepage https://github.com/lvpengwei/LVThemeKit
License MIT
Platforms ios 8.0
Authors

说明

App 多区域皮肤 UIKit Category

LVThemeKit/ObjC 适用于 OC 项目

LVThemeKit/Swift 适用于 Swift 项目

功能

  • UIKit Category
    • UIView
    • UIImageView
    • UILabel
    • UIButton
    • UISlider
  • QuartzCore Category
    • CALayer
    • CAShapeLayer
  • Resource
    • LVThemeColor
    • LVThemeImage
    • LVThemeString
    • LVThemeAttributedString
  • 其他,可以很容易的扩展

用法

  • UIView
// OC
self.label.viewTK.theme.backgroundColor = [LVThemeColor background];
self.label.viewTK.other.backgroundColor = [LVThemeColor otherBackground];
// Swift
label.viewTK.theme.backgroundColor = LVThemeColor.background
label.viewTK.other.backgroundColor = LVThemeColor.otherBackground
  • UIButton
    // OC
    [self.button.buttonTK.theme setImage:[LVThemeImage image] forState:UIControlStateNormal];
    // Swift
    button.buttonTK.theme.setImage(LVThemeImage.image, for: .normal)
  • CALayer
    // OC
    self.layer.layerTK.theme.borderColor = [LVThemeColor background];
    // Swift
    layer.layerTK.theme.borderColor = LVthemeColor.background

配置

  • LVThemeKitConfig
    • generators: 监听主题变化的通知数组,根据配置的数量生成主题数量
    • applyProperty: 当配置多套主题时,自定义应用顺序,默认是数组顺序
      // OC
      LVThemeKitConfig *conf = [[LVThemeKitConfig  alloc] init];
      config.generators = @[[DayNightObserver class]];
      LVThemeKit.config = conf;
      // Swift
      let conf = LVThemeKitConfig()
      conf.generators = [DayNightObserver.self]
      LVThemeKitConfig.config = conf

扩展

  • 扩展类,参考UIView/CALayer
  • 扩展属性
    • 支持 KVC,参考UIView.backgroundColor
    • 不支持 KVC,参考UIButton.setTitle:forState:
  • 替换已有的类,比如UIView.viewTK,可以新加一个属性UIView.x_viewTK

例子

安装

Cocoapods

pod 'LVThemeKit/ObjC'

或者

pod 'LVThemeKit/Swift'

Latest podspec

{
    "name": "LVThemeKit",
    "version": "1.0.0",
    "summary": "Theme kit.",
    "description": "Theme kit for UIKit.",
    "homepage": "https://github.com/lvpengwei/LVThemeKit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "lvpengwei": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/lvpengwei/LVThemeKit.git",
        "tag": "1.0.0"
    },
    "swift_version": "5.0",
    "default_subspecs": "ObjC",
    "subspecs": [
        {
            "name": "ObjC",
            "source_files": [
                "Source/ObjC/**/*.{h,m}"
            ],
            "prefix_header_contents": "#ifdef __OBJC__n#import n#import n#import "LVThemeColor.h"n#import "LVThemeImage.h"n#import "LVThemeKit.h"n#import "LVThemeString.h"n#import "UIButton+LVThemeKit.h"n#import "UILabel+LVThemeKit.h"n#import "UIView+LVThemeKit.h"n#import "UISlider+LVThemeKit.h"n#import "UIImageView+LVThemeKit.h"n#import "CALayer+LVThemeKit.h"n#import "CAShapeLayer+LVThemeKit.h"n#endif"
        },
        {
            "name": "Swift",
            "source_files": [
                "Source/Swift/**/*.swift"
            ]
        }
    ]
}

Pin It on Pinterest

Share This