ColorAdjuster是一个库,可以根据基础颜色创建新的颜色(通过HBS或RGB),并创建渐变视图。
要运行示例项目,克隆仓库,然后首先从Example目录运行pod install。
ColorAdjuster可通过CocoaPods获得。要安装它,只需在您的Podfile中添加以下行
pod "ColorAdjuster"let color = UIColor(hex: 0xB7EAE7)let adjustmentColor = color.colorWithHBSComponent(hue: hueValue, brightness: brightnessValue, saturation: saturationValue)
adjustmentColorView.backgroundColor = adjustmentColorif let hbs = adjustmentColor?.colorHBS() {
print("Hue = \(hbs.hue)")
print("Bridhtness = \(hbs.brightness)")
print("Saturation = \(hbs.saturation)")
}let adjustmentColor = color.colorWithRGBComponent(red: rValue, green: gValue, blue: bValue)
targetView.backgroundColor = adjustmentColorif let rbg = adjustmentColor?.colorRGB() {
print("Red = \(rbg.red)")
print("Green = \(rbg.green)")
print("Blue = \(rbg.blue)")
}let targetView = UIView(frame: frame)
let colors: [CGColor] = [UIColor.redColor().CGColor, UIColor.magentaColor().CGColor]
view.addSubView(targetView)指定位置
let locations: [CGFloat] = [0.0, 1.0]
targetView.gradientLayer.insertLayerVerticallyGradient(colors: colors, locations: locations)指定startPoint和endPoint
let startPoint = CGPointMake(1, 0.5)
let endPoint = CGPointMake(0, 0.5)
targetView.gradientLayer.insertLayerVerticallyGradient(colors: colors, startPoint: startPoint, endPoint: endPoint)指定Angle = 零
targetView.gradientLayer.insertLayerVerticallyGradient(colors: colors, angle: .Zero)指定Angle = 四十五
targetView.gradientLayer.insertLayerVerticallyGradient(colors: colors, angle: .FortyFive)指定九十
targetView.gradientLayer.insertLayerVerticallyGradient(colors: colors, angle: .Ninety)public convenience init(hex: Int, alpha: CGFloat = 1)public func colorWithHBSComponent(hue hue: CGFloat, brightness: CGFloat, saturation: CGFloat) -> UIColor?public func colorHBS() -> ColorAdjuster.HBSProperties?public func colorWithRGBComponent(r r: CGFloat, g: CGFloat, b: CGFloat) -> UIColor?public func colorRGB() -> ColorAdjuster.RGBProperties?public func insertLayerVerticallyGradient(colors colors: [CGColor], locations: [CGFloat])
public struct HBSProperties {
public var hue: CGFloat = 0
public var brightness: CGFloat = 0
public var saturation: CGFloat = 0
public var alpha: CGFloat = 1
}public struct RGBProperties {
public var r: CGFloat = 0
public var g: CGFloat = 0
public var b: CGFloat = 0
public var alpha: CGFloat = 1
}ikemai
ColorAdjuster受MIT许可证的许可。有关更多信息,请参阅LICENSE文件。