美文网首页
获取颜色的RGB值

获取颜色的RGB值

作者: 沈正方 | 来源:发表于2018-05-29 09:25 被阅读35次
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值

      本文链接:https://www.haomeiwen.com/subject/iplsbxtx.html