2017-10-21 27 views
0

나는 jQuery과 셀 배경 색상으로 재생하고 내가 이런 식으로 할 경우 작동 :jQuery과 셀 배경의 사용자 정의 색상

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { 
    cell.backgroundColor? = UIColor.yellow 
} 

을하지만 사용자 정의 색상을

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { 
    cell.backgroundColor? = UIColor(red: 255, green: 197, blue: 2, alpha: 1) 
} 

을 시도하는 경우 그렇지 않은 무엇 맞춤 RGB 색상을 만들려면 어떻게해야합니까?

+2

사용. 'UIColor (빨강 : 255/255., 녹색 : 197/255., 파랑 : 2/255., 알파 : 1)' – Larme

+0

[UIColor가 RGBA 값으로 동작하지 않을 가능성이 있습니다 ] (https://stackoverflow.com/questions/24310696/uicolor-not-working-with-rgba-values) – Larme

답변

0

당신은 작성해야 :

UIColor(red: 255/255, green: 197/255, blue: 2/255, alpha: 1) 
+0

물론 CGFloat ... 고맙습니다. – Dawy

1

주의 깊게 문서를 읽을 필요가 있기 때문에 편리 초기화를

1 단계

extension UIColor { 
    convenience init(r: CGFloat, g: CGFloat, b: CGFloat) { 
     self.init(red: r/255, green: g/255, blue: b/255, alpha: 1) 
    } 
} 

사용

//let color = UIColor(red: 255/255, green: 197/255, blue: 2/255, alpha: 1) ☠️ 
let color = UIColor(r: 255, g: 197, b: 2) //