This is one of those times when I thought I was going to learn one thing, but ended up with a completely different lesson. I didn't post last night because I fought with it, said screw it, went to bed and played there for two hours thinking about it. I just couldn't let go of it.
I started off by building a simple app called StinkLock. 4 labels, 3 sliders and a button. The idea was once the sum of the sliders equaled something or some sequence of values, the button would become active to tap and show a modal screen. Related aside, practically every little thing I do to reinforce an idea always becomes some way of telling my kid they stink.
I put everything in the main.storyboard
. I put the UILabels
that showed the value rounded to whole numbers above the UISlider
. I put the UILabels
and UISliders
in their own StackView
. I put those three in a stack together, constrained to center horizontal and vertical. I added my @IBActions
and @IBOutlets
. All I really needed to do was decide on the functions to change the button state from disabled
to active
, add the segue and call it done.
I ran my app in the simulator. Slider buttons didn't move. Ran it on my phone. Same thing. I added the slider.minumumValue
and slider.maximumValue
properties in the viewDidLoad()
. Didn't budge. I tinkered with the content mode properties. Nothing. That's when I went to bed to brood over it. 3 hours of sleep.
After a bit of hard googling and slamming back an energy drink, I found it. Every time I embedded the elements into the StackView
, my leading and trailing were clipped, by the time I had it three stacks deep, the slider had no room to wiggle. I removed all of my constraints, rebuilt the layout. It works fine. Exactly what I wanted it to do. I'm sure I muttered some vulgarities to myself.
I did watch a tutorial on optionals, read a few articles on them. But nothing is going to stick with me like the sleep depriving struggle I had with a simple UISlider
.
Top comments (0)