Latest 0.0.3
Homepage https://github.com/pujiaxin33/JXGradientKit
License MIT
Platforms ios 9.0, requires ARC
Frameworks UIKit
Authors

常用控件背景渐变色Kit

原理

重载UIView的layerClass方法,返回CAGradientLayer,达到控件背景为渐变色。

控件

  • JXGradientLabel
  • JXGradientView
  • JXGradientButton
  • JXGradientTextField
  • JXGradientTextView

JXGradientLabel实现示例

open class JXGradientLabel: UILabel {
    open class override var layerClass: Swift.AnyClass {
        get {
            return CAGradientLayer.classForCoder()
        }
    }

    public override init(frame: CGRect) {
        super.init(frame: frame)

        initializeViews()
    }

    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        initializeViews()
    }

    open func initializeViews() {
        gradientLayer.jx_direction = .leftToRight
    }

    public var gradientLayer: CAGradientLayer {
        get {
            return self.layer as! CAGradientLayer
        }
    }
}

JXGradientLayerDirection

public enum JXGradientLayerDirection {
        case leftToRight
        case topToBottom
        case leftTopToRightBottom
        case leftBottomToRightTop
    }
  • 使用
    gradientLabel.gradientLayer.jx_direction = .leftToRight
    gradientLabel.gradientLayer.colors = [firstColor, secondColor]

安装

use_frameworks!
target '<Your Target Name>' do
    pod 'JXGradientKit'
end

Latest podspec

{
    "name": "JXGradientKit",
    "version": "0.0.3",
    "summary": "u5e38u7528u63a7u4ef6u80ccu666fu6e10u53d8u8272Kit",
    "homepage": "https://github.com/pujiaxin33/JXGradientKit",
    "license": "MIT",
    "authors": {
        "pujiaxin33": "[email protected]"
    },
    "platforms": {
        "ios": "9.0"
    },
    "swift_version": "4.2",
    "source": {
        "git": "https://github.com/pujiaxin33/JXGradientKit.git",
        "tag": "0.0.3"
    },
    "frameworks": "UIKit",
    "source_files": [
        "Sources",
        "Sources/*.{swift}"
    ],
    "requires_arc": true
}

Pin It on Pinterest

Share This