Specifed color changing in string. Swift iOS -


i'm wondering how make colorful string.

what mean is:

i need string example

firstletter - white, second - blue, third - red , forth - orange , fifth - white , on in loop.

i googled line of code:

mymutablestring.addattribute(nsforegroundcolorattributename, value: uicolor.redcolor(), range: nsrange(location:2,length:4)) 

but gets location , length, how make changing color in specified order?

try this:

let color : [uicolor] = [.white, .blue, .red, .orange]   let plainstring = "hello world" let str = nsmutableattributedstring(string: plainstring)  var in 0..<plainstring.characters.count {     let range =  nsmakerange(i, 1)     let newcolor = color[i % color.count]      str.addattribute(nsforegroundcolorattributename, value: newcolor, range: range) } 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -