Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Is there an extension for the uibutton in swift?


Asked by Emanuel Bowen on Dec 13, 2021 Swift



The eighth item in my Swift Tool Belt is an extension for UIButton. This extension adds a bit of functionality that is sorely missing from UIButton, giving you the ability to set the background color for different button states. A UIButton can be in many states: default, selected, highlighted, or disabled.
Furthermore,
To create a new UIButton, set its width, height, and position the button within a view programmatically, you can do with CGRect class. For example: Setting text on a button is very simple. It can be done with a function call setTitle (_ title: String?, for state: UIControl.State) . A title on the button can be set for different button states.
Keeping this in consideration, To create a regular, system type button in Swift you will need to create a new instance of UIButton class. To create a button of a different type like for example ButtonType. close, you will do: To create a new UIButton, set its width, height, and position the button within a view programmatically, you can do with CGRect class. For example:
Indeed,
A UIButton can be in many states: default, selected, highlighted, or disabled. There are also many items on a UIButton that you can customize for the different states. For instance, you can change the title, font, text color, shadow color, image, and background image, but not the background color. For some reason, Apple decided not to include it.
In addition,
If you do not specify attributes for a particular state, the UIButton class provides a reasonable default behavior. For example, a disabled button is normally dimmed and does not display a highlight when tapped.