小编lch*_*amp的帖子

如何创建几个缓存的UIColor

我的代码中有自定义颜色.我多次使用它们,我想只分配一次.

情况/问题

如果我们看一下UIColor标题,我们可以看到以下内容:

[...]

// Some convenience methods to create colors.  These colors will be as calibrated as possible.
// These colors are cached.

open class var black: UIColor { get } // 0.0 white

open class var darkGray: UIColor { get } // 0.333 white

[...]
Run Code Online (Sandbox Code Playgroud)

我创建了一个extensionUIColor,如下所示:

import UIKit

extension UIColor {

    class func colorWithHexString(_ hex: String) -> UIColor {

        print("\(#function): \(hex)")

        // some code, then it return a UIColor

        return UIColor(
            red: CGFloat((rgbValue & 0xFF0000) >> …
Run Code Online (Sandbox Code Playgroud)

uicolor swift swift-extensions

4
推荐指数
1
解决办法
567
查看次数

标签 统计

swift ×1

swift-extensions ×1

uicolor ×1