I have a custom coloured background that the user can choose, this however means when they change the colour, the label is invisible because it is the same as the background and I do not want this. The code I have is: opacityLabel.textColor = bgView.backgroundColor; In this bit of code the colour is the same at the start but doesn’t change when I adjust the background colour, I also need the colour to continually change with the background colour, I was wondering what I could replace with “=” to make the label do the opposite colour. I can’t do “!=” because that means is not equal to rather than opposite! If you can’t do it this way could you provide me with a way of doing it?
I have a custom coloured background that the user can choose, this however means
Share
The first thing you’ll need to do is calculate the opposite colour to the
backgroundColor, and then assign it to thetextColorproperty.To do this you’ll need to use the
getRed:green:blue:alpha:method onbackgroundColor. This will give you values between 0.0 and 1.0 for each component of your colour.Then use the
UIColorclass methodcolorWithRed:green:blue:alpha:to create a newUIColor, but use (1.0 – component value) for each of the components.Then finally assign your new colour to
opacityLabel.textColor