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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -