Initializer

init(type:)

Creates and returns a new button of the specified type.

Declaration

convenience init(type buttonType: UIButton.ButtonType)

Parameters

buttonType

The button type. See UIButton.ButtonType for the possible values.

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.ButtonType.custom—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.

See Also

Creating Buttons

enum UIButton.ButtonType

Specifies the style of a button.