Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Will Schwarz
2,795 PointsSet dynamic Fact Text Color
What code could I add to set the Fact Text Color to change dynamically, but also make sure it's not the same as the background color? Is there a way to utilize the same color array?
1 Answer
Jonathan McCottry
6,606 PointsOne cool thing you can do is set up some colors you would like to see in your app and give them attributes like light and dark. This is important because if you have a light background, you want to use a dark color and vise versa. So when you are creating your new view after a button click, you will want to programmatically pick a background randomly with your facts then look at the attributes of the color and randomly pick a text color that is the opposite of background.
get colors() { bgcolor = randomgetcolor(any)
if (bgcolor.attribute == darkcolor) { txtcolor.attribute = randomgetcolor(light) } else { txtcolor.attribute = randomgetcolor(dark) }
Will Schwarz
2,795 PointsWill Schwarz
2,795 PointsThanks Jonathan!