Image for post
Image for post
Photo by Ramshid ekl on unsplash.com

There are numerous reasons a user could want to clear a value inside a text field, whether it’s a typo or just for entering completely new things and everyone knows how cumbersome it can become to clear long text on a mobile device inside a small field.

Image for post
Image for post
Clear button inside a text field

The TextField element of the SwiftUI framework does not have such a feature built-in, so you’d have to build your own solution for that. In this article I want to show how to accomplish a simple clear button inside a SwiftUI TextField element.

Note: XCode 11.x, Swift 5.x, and iOS 13.x are required. It’s assumed you already have some knowledge about programming in Swift and SwiftUI, how to build apps, and implement your own views in them. This is not a tutorial to teach you the basics.


Image for post
Image for post
Photo by Aditya Vyas on Unsplash.

In app development, you often have the requirement for some kind of collapsible view. With the release of iOS 14 and Xcode 12, we will have the luxury of DisclosureGroup view elements to achieve that for us. But until its release — and for apps that need some backward compatibility — you have to provide your own custom solution for that.

In this article, I want to show you a simple approach to creating your own custom collapsible view in SwiftUI. Let’s get started!

Note: XCode 11.x, Swift 5.x, and iOS 13.x are required. It’s assumed you already have some knowledge about programming in Swift and SwiftUI, how to build apps, and implement your own views in them. …

About

Martin Albrecht

Mobile- / Frontend Developer

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