javascript - Swift equivalent of '#' + Math.random().toString(16).slice(2, 8) -
the javascript:
function randomcolor() { return '#' + math.random().tostring(16).slice(2, 8); }
what swift equivalent?
i'm assuming uikit here.
swift ui typically uses uikit uicolor
type represent color.
you can use drand48
random color between 0 , 1, convert float , return ui color parameters:
func randomcolor() -> uicolor { return uicolor(red: cgfloat(drand48()), green: cgfloat(drand48()), blue: cgfloat(drand48()), alpha: 1.0 ) }
update - found online, similar earlier solution - might make sense link here: https://gist.github.com/skreutzberger/32be80e2ebef71dfb793
Comments
Post a Comment