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

Alexis Marrero
Alexis Marrero
4,275 Points

how do i make a label show different words when i press a button.SWIFT 4

IM TRAYING TO MAKE THE LABEL SHOW DIFFERENT WORDS WHEN I PRESS THE BUTTON... LIKE I WANT TO MAKE AN ARRAY AND EACH TIME I PRESS THE BUTTON THE LABEL CHANGE TO THE OTHER WORD.. SWIFT 4

1 Answer

Simon Di Giovanni
Simon Di Giovanni
8,429 Points

Hi there

You need to allocate a string to the label's '.text'

So for example if your label is named Title

Title.text = "Your String Here"

So if you want to do that when a button is pressed, you need to first make an action from the button using the assistant editor, then inside the action function, put your Title.text = "Your string here"

Hope this helps!