Type Method

buttonWithType:

Creates and returns a new button of the specified type.

Declaration

+ (instancetype)buttonWithType:(UIButtonType)buttonType;

Parameters

buttonType

The button type. See UIButtonType 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 UIButtonTypeCustom—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

UIButtonType

Specifies the style of a button.