SwiftUI — First Impressions and a Quick Tip for Changing Placeholder Text Color

Photo by Victoria Heath on Unsplash

When SwiftUI was first announced at WWDC 2019, I was hesitant to give it a try. I thought it was WYSIWYG and being a purest I didn’t want anything to do with it. It wasn’t until it was added to the iOS course I’m taking at Devslopes Academy that I gave it a shot.

First impression, SwiftUI is no more WYSIWYG than using storyboard in UIKit. It’s actually the best of both worlds, because what you set using the Attributes Inspector actually gets written in the code so you can see what aspects have been set and change it in the code without having to go back to the Attributes Inspector to do so. And whether you are hand coding or using the Attributes Inspector to style your code, having the canvas update automatically as changes are made is super convenient.

Right out of the gate I was impressed with how quickly the UI came together. Having used stack views in UIKit, the concept of VStacks, HStacks and ZStacks in SwiftUI was an easy transition. And unlike ScrollViews in UIKit, they work right out of the box in SwiftUI. Bonus!

Not only are building interfaces in SwiftUI fast, I feel like my designs come out looking more elegant. Adding shadows and rounding corners are a breeze and creating animations are just as easy. Don’t even get me started with tableViews; gone are the days of writing dozens of lines of code, with SwiftUI you only need a few lines of code to create a list, it’s never been easier.

While SwiftUI does amazing things to help set up your UI with ease, it is still in its infancy so it doesn’t yet handle every situation. The first issue I ran into was the inability to change the color of placeholder text in a textField. It appears this feature hasn’t been built in yet, so after scouring the internet, here is the fix I found.

Create a struct for a custom text field.

Then replace the TextField code with the following. Make sure to change the text parameter to point to your variable for that field.

For my initial assessment I would equate learning SwiftUI after using UIKit to going to another country and driving on the other side of the road, where at times your instincts will try to pull you in the wrong direction. It’s not hard, it will just take some getting used to.

Overall SwiftUI seems very well thought out and I appreciate that it’s easy to read and for the most part simple to implement. I am excited to learn all that it can do.

To delve deeper into SwiftUI, I am currently working my way through Paul Hudson’s, 100 days of SwiftUI course. I highly recommend it.

A few other great resources I stumbled upon are GoshDarnSwiftUI and Rob Sturgeon’s Medium article, The Complete SwiftUI Documentation You’ve Been Waiting For.

Happy coding!

--

--

--

Web / iOS Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

[Tool] Struggle with designing iOS text? Try iOS Font Family List!

WWDC Phobia

Add a tap gesture to a part of a UILabel -iOS Swift

All you need to know about completion handler in Swift

iPhone back tap for the deaf-blind

Singleton vs Dependency Injection in Swift

Move To Top of Tab on selecting same tab from Tab Bar in SwiftUI

Configurations and Code, a way to separate them (iOS)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kelly O’

Kelly O’

Web / iOS Developer

More from Medium

SwiftUI — Font templates made easy

Working with GroupBox in SwiftUI

Introduction to Alignments : The Alignment Process

How to use SplitView SwiftUI