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

iOS Build a Weather App with Swift Simple Data Structures Bootstrapping the UI

dexter foo
dexter foo
8,233 Points

Changing opacity

Just curious, in Pasan's video, he changed the opacity of the label by going to Attribute inspector -> Label -> color and setting the opacity to 50%. Would i get the same result if i select the label, go to Attribute inspector -> View -> alpha and set it to 0.5. I tried both methods and both seems to change the label's opacity to 50%. But as the second method involves going to the View component of the attribute inspector, i'm afraid there might some other underlying changes that i'm not aware of or failed to notice

1 Answer

Nick Kohrn
Nick Kohrn
38,025 Points

Dexter,

What Pasan changed the alpha (opacity) of was the text of the label. If you would change the alpha via the 'View' section of the Attributes Inspector, then you would be changing the alpha of the entire view (i.e. the whole label, background and all). To illustrate this, I created a simple image that includes two labels with the background property set to blue from the 'View' section in the Attributes Inspector:

alpha example

By changing the alpha via the color menu, you can see that this property changes the label's text color, but does not affect the background color of the label:

text color alpha property

By changing the alpha of the view, you are changing the alpha of the entire view (background included), which a UILabel is a subclass of:

view alpha property

I hope this helps clarify the difference for you!

dexter foo
dexter foo
8,233 Points

Hmm wow thanks for being so detailed! Thats what i initially thought as well. But however, i had the Object selected when i entered the Attribute inspector and when i changed the alpha value under view, only the opacity of the Object changed and the view remained the same. Maybe i couldnt differentiate it properly after facing the monitor for a long time.