获取颜色的RGB值

func getRGBValue() -> (CGFloat, CGFloat, CGFloat) {
  guard let components = self.cgColor.components else {
    fatalError("该颜色不是通过RGB创建的")
  }
  return (components[0] * 255, components[1] * 255, components[2] * 255)
}    

func getRGBValue1() -> (CGFloat, CGFloat, CGFloat) {
  var r: CGFloat = 0
  var g: CGFloat = 0
  var b: CGFloat = 0
  var alpha : CGFloat = 0
  getRed(&r, green: &g, blue: &b, alpha: &alpha)
    return (r * 255, g * 255, b * 255)
}

你可能感兴趣的:(获取颜色的RGB值)