Customizing UIButton in iOS 15

Do repost and rate:

Buttons are an essential element in iOS apps. If you are developing an app using UIKit, you will probably use UIButton class to create buttons. Creating a button is a straightforward process, but it becomes problematic when it comes to customizations. Soon you will find yourself writing hacks for achieving your desired result. We all have been there, and we have done it. You are not alone. Luckily, iOS 15.0 gives us a new method to customize Buttons much easier using UIButton.Configuration. Let’s get started!

Configuration types in UIButton

UIButton.Configuration comes in four different types, namely plain, filled, gray, and tinted. In this article, we will be focusing only on filled configuration. I will leave the rest of the configurations for you to experiment.

 

var configuration = UIButton.Configuration.filled()

 

Setting a title in a UIButton

Setting a title is done by using the configuration’s title property.

 

configuration.title = "Start download"

 

Setting a subtitle in a UIButton

Again, we can make use of the configuration’s subtitle property to set a subtitle. It would be tough to set a subtitle without the configuration API.

 

configuration.subtitle = "(Downloads a random image)"

 

Changing the background color of a UIButton

The color of the UIButton’s background view can be changed using baseBackgroundColor property.

 

configuration.baseBackgroundColor = .systemOrange

This article was originally published at ohmyswift.com. Click here to read the full article.

About the author ?????

Rizwan Ahmed — iOS Engineer.

Twitter ?? https://twitter.com/rizwanasifahmed

Like our articles? Support us ??https://www.buymeacoffee.com/ohmyswift

Regulation and Society adoption

Ждем новостей

Нет новых страниц

Следующая новость