swift - UIColor initializer (cannot find an initializer of type 'UIColor' that accepts ....) error -
this question has answer here:
i know not appropriate way purpose of learning have picker control 4 components , 255 rows in each change 'view' background color based on rgb-alpha. know uicolor(red: <#cgfloat#>, green: <#cgfloat#>, blue: <#cgfloat#>, alpha: <#cgfloat#>)
accepts 4 float numbers parameter each color error:
cannot find initializer type 'uicolor' accepts argument list of type '(red: float, green: float, blue: float, alpha: float)'
wrong?
func pickerview(pickerview: uipickerview, didselectrow row: int, incomponent component: int) { var newbackgroundcolor = uicolor() var redcode: float = 0.0 var greencode: float = 0.0 var bluecode: float = 0.0 var alphacode: float = 0.0 if component == 0 { switch row { case 0..<256: redcode = float(row/255) newbackgroundcolor = uicolor(red: redcode, green: greencode, blue: bluecode, alpha: alphacode) default: break } } else if component == 1 { switch row { case 0..<256: greencode = float(row/255) newbackgroundcolor = uicolor(red: redcode, green: greencode, blue: bluecode, alpha: alphacode) default: break } } else if component == 2{ switch row { case 0..<256: bluecode = float(row/255) newbackgroundcolor = uicolor(red: redcode, green: greencode, blue: bluecode, alpha: alphacode) default: break } } else { switch row { case 0..<256: alphacode = float(row/255) newbackgroundcolor = uicolor(red: redcode, green: greencode, blue: bluecode, alpha: alphacode) default: break } } self.view.backgroundcolor = newbackgroundcolor }
use cgfloat
not float
check api docs when error this
Comments
Post a Comment