Creates and returns a new button of the specified type.
SDKs
- iOS 2.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
Framework
- UIKit
Declaration
convenience init(type buttonType: UIButton.Button Type)
Parameters
buttonType
The button type. See
UIButton
for the possible values..Button Type
Return Value
A newly created button.
Discussion
This method is a convenience constructor for creating button objects with specific configurations. If you subclass UIButton
, this method does not return an instance of your subclass. If you want to create an instance of a specific subclass, you must alloc/init the button directly.
When creating a custom button—that is a button with the type UIButton
—the frame of the button is set to (0, 0, 0, 0) initially. Before adding the button to your interface, you should update the frame to a more appropriate value.