我收到此错误:“当我尝试更改颜色时,对成员'下标'的模糊引用”:
struct color {
var r : Float
var g : Float
var b : Float
}
func setPixels(image:[color], pixel: Int) {
let alpha: Float = 1.0
let pixelView = view.viewWithTag(pixel) as! UIImageView
pixelView.backgroundColor = UIColor(
red: image[pixel].r, //Error: Ambiguous reference to member 'subscript'
green: image[pixel].g,
blue: image[pixel].b,
alpha: alpha)
}
答案 0 :(得分:2)
浮动它与CGFloat不同。你必须将CGFloat传递给UIColor。注意:您应该以大写字母开头命名结构。
{{1}}