DEV Community

loading...

Blog Vent 2 (Actions & Outlets)

keepoSteepo
・1 min read

This time around, I learned how to connect my code to the views and controls created in the storyboard so that they respond to user actions. There are two kinds of connections between storyboards and code; actions and outlets. Outlets connect variables in your code to objects in your storyboard in order to access those objects within your code and get information or make changes when the app is running. Actions connect controls like switches and buttons to methods in your code. I put this in to practice by building the color mix app. This app has a display screen at the upmost part of the screen. Below, three buttons and three sliders, each one assigned a color between red, blue and green. The display screen and sliders are outlets and the buttons are actions. As the button is pressed, the display screen will show the color associated with that button, the slider is the intensity of the color from min to max. The sliders can be in a number of positions and the buttons can be combined by only having blue and green on or red and blue, etc. After, I polished the interface and gave it a clean look. The background is silver, the buttons are black except when pressed, then they change accordingly to their color and the sliders color changes according to how much of the min/max is showing.

I almost forgot; I also added a reset button that does exactly that. The buttons are enabled when the switch is on, otherwise they are nonfunctional.

Discussion (0)