Sometimes, we would require a button to show a loader with appropriate text when a long-duration task is done, such as downloading an image. Before iOS 15, we had to write a custom button or do some hacks to show a simple loader or an UIActivityIndicator inside an UIButton. Now, it is not the case anymore. UIButtonConfiguration provides
showsActivityIndicator, a simple property using which we can hide/show a loader inside a button.
We recommend that you visit this article if you are unfamiliar with UIButtonConfiguration.
To hide the loader or activity indicator
To show the loader or activity indicator
Customizing the color of the loader or activity indicator
We can also customize the color of the loader or activity indicator by using the
We can use two options: choose the default ones (grayscale, preferredTint, or monochromeTint) or use our custom color.
Default color usage
Custom color usage
The UIButton provides us a
configurationUpdateHandler where we can change the button’s appearance using the configuration. The
configurationUpdateHandler is triggered when the
setNeedsUpdateConfiguration method is called on the button.
About the author
- Rizwan Ahmed - iOS Engineer. Twitter - https://twitter.com/rizwanasifahmed
- How to filter screenshots, cinematic videos, and depth-effect photos in PHPickerViewController
- Implementing a custom native calendar using UICalendarView in iOS16 and Swift
- Exploring Deque in Swift Collections
- Replacing UIImagePickerController with PHPickerViewController
- Embracing Localization in Image Assets
- An effective way to clear entire Userdefaults in Swift
Like our articles? Support us!