ViewCSS 1.0.8

ViewCSS 1.0.8

Eric Chapman维护。



ViewCSS 1.0.8

  • 作者:
  • Eric Chapman

ViewCSS

CI Status Codecov Version License Platform

ViewCSS是用于iOS应用程序的类似CSS的插件。它提供了一种简单的接口来定义UIView元素的不同的属性。它旨在允许应用程序开发人员/设计师通过简单的接口实现CSS重用方法,以及在运行时覆盖值。它不打算取代自动布局、NIB等。

版本

  • v1.0.9
    • 2019年更新版权信息
    • 通过使用“nil”参数删除了一些方法(对API没有影响
  • v1.0.8
    • 添加了“cssAttributedText”属性,使得您只需创建一次字符串即可
  • v1.0.7
    • 向“String”类添加了“cssText”函数,简化文本高度的预测
  • v1.0.6
    • 定义swift_version = 4.0
  • v1.0.5
    • 修复了“cssText”中的emojis问题
  • v1.0.4
    • 更新了“generateCSSText”方法,允许在类方法中返回NSAttributedText以用于文本高度预测
  • v1.0.3
    • 解决了“cssText”将背景颜色应用到UIButton标题标签的问题
  • v1.0.2
    • 为UIButton添加了“cssText”支持
  • v1.0.1
    • 修复了“cssText”不正确地提取缓存设置的bug
  • v1.0.0
    • 首次全版本发布

示例

文档位于此处的Wiki页面上。

import UIKit
import ViewCSS

class MyCustomViewController: UIViewController {
    @IBOutlet weak var label1: UILabel?
    @IBOutlet weak var label2: UILabel?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Set the global CSS dictionary (see later section on this)
        let css: [String:Any] = [
            ".bold" : [
                "font-weight" : "bold"
            ],
            "my_custom_view_controller.label1" : [
                "font-size" : "16px",
                "text-align": "left",
                "color" : "red",
            ],
            "my_custom_view_controller.label2" : [
                "font-size" : "12px",
                "text-align": "right",
                "color" : "white",
            ],
        ]
        ViewCSSManager.shared.setCSS(dict: css)
        
        // ...
        
        self.css(object: self.label1, class: "label1")
        self.css(object: self.label2, class: "bold label2")
    }
    
    var setText(firstName: String, lastName: String) {
        self.label1?.cssText = "\(firstName)<span class=\"bold\">\(lastName)</span>"
    }
    
}

要求

支持iOS 8.0及以上版本

安装

ViewCSS 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod 'ViewCSS'

许可

ViewCSS 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。