Baby steps in swift 2: Changing color of objects and backgrounds
Apparently everybody's favourite color isn’t grey so I played around with different ways of modifying color in swift. For this I didn’t do a specific tutorial so instead stack overflow was my most valued help. Love that community!
Also the label that said “Current color” changed both its text and textcolor. Push “My button” again and the creeper and text changes color again.
The class UIColor is used to define a constant that is called every time the button is pressed, making the creeper change color, that same constant also changes the color of the text for each push of the button. To make the actual text change a constant was created which had the names of the colors used in the same order as the colors in the color constant.
Changing the RGB-sliders in the bottom changes the color of the background, the values of the slider (0–1) is passed to a function that with the help of the UIColor class translates the float-numbers to each responding tint of red, green or blue.
The reset button makes the creeper its original white color by setting the color of the creeper to the first position in the color constant, that so happens to be is referencing the color white from UIColor. For the next part of this series I’m probably gonna show the code also, as I’m not sure if these explanations make any sense without it.
This is a great article if you wanna make a RGB color slider: http://stackoverflow.com/questions/34459115/cannot-convert-value-of-type-float-to-expected-argument-cgfloat
Describes a representation of color and opacity (alpha value).developer.apple.com
Github repo for code: https://github.com/cc-lemon/ios_color_slider