Linus Torvalds, the creator of the massively popular Linux operating system, once said “talk is cheap; show me the code.” What he was trying to say in his inimitable way is that seeing code that solves a problem well is often the most important thing in our industry – it’s important to talk about problems and to explore them thoroughly on a conceptual level, but ultimately writing code that solves the problem is what makes products ship.
I use storyboards for most projects I teach – they are easier for beginners to learn, they give us the ability to see how a design looks as we’re building it, and they can even show you previews across multiple devices and orientations at the same time.
However, in this project we’re going to build the user interface entirely in code. There will still be a storyboard, but we’re not going to touch it – we’ll create our labels, buttons, and Auto Layout constraints entirely in Swift.
This is our “show me the code” moment: we’re going to look at exactly how to build complex iOS layouts programmatically so that everything is entirely under your control. It’s not hard to do, but it does take a lot of time – we need to create, configure, and place every view by hand. However, I think you’ll learn a lot from the experience, because after today I think you’ll know for sure whether you prefer using storyboards or creating UI in code!
Today you have two topics to work through, and you’ll learn about text alignment, layout margins, UIFont
, and more.
Once you’re done, there’s something I’d like you to keep in mind: whether you prefer making user interfaces in storyboards or programmatically, it’s important you know how to do both. It’s one thing having your preference, but when you join a company you need to be able to solve problems as a team.
Need help? Tweet me @twostraws!
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
The 100 Days of Swift is a free collection of videos, tutorials, tests, and more to help you learn Swift faster. Click here to learn more, or watch the video below.
Link copied to your pasteboard.