Inherits from SPDisplayObjectContainer : SPDisplayObject : SPEventDispatcher : NSObject
Declared in SPButton.h

Overview

An SPButton is a simple button composed of an image and, optionally, text.

You can pass a texture for up- and downstate of the button. If you do not provide a down state, the button is simply scaled a little when it is touched.

In addition, you can overlay a text on the button. To customize the text, almost the same options as those of SPTextField are provided. In addition, you can move the text to a certain position with the help of the textBounds property.

To react on touches on a button, there is special event type: SPEventTypeTriggered. Use this event instead of normal touch events - that way, the button will behave just like standard iOS interface buttons.

Tasks

Initialization

Properties

  •   scaleWhenDown

    The scale factor of the button on touch. Per default, a button with a down state texture won’t scale.

    property
  •   alphaWhenDisabled

    The alpha value of the button when it is disabled.

    property
  •   enabled

    Indicates if the button can be triggered.

    property
  •   text

    The text that is displayed on the button.

    property
  •   fontName

    The name of the font displayed on the button. May be a system font or a registered bitmap font.

    property
  •   fontSize

    The size of the font.

    property
  •   fontColor

    The color of the font.

    property
  •   upState

    The texture that is displayed when the button is not being touched.

    property
  •   downState

    The texture that is displayed while the button is touched.

    property
  •   textBounds

    The bounds of the textfield on the button. Allows moving the text to a custom position.

    property
  •   isDown

    Indicates if the button is currently being pressed.

    property
  •   color

    The color of the button’s state image. Just like every image object, each pixel’s color is multiplied with this value.

    property

Properties

alphaWhenDisabled

The alpha value of the button when it is disabled.

@property (nonatomic, assign) float alphaWhenDisabled

Discussion

The alpha value of the button when it is disabled.

Declared In

SPButton.h

color

The color of the button’s state image. Just like every image object, each pixel’s color is multiplied with this value.

@property (nonatomic, assign) uint color

Discussion

The color of the button’s state image. Just like every image object, each pixel’s color is multiplied with this value.

Declared In

SPButton.h

downState

The texture that is displayed while the button is touched.

@property (nonatomic, strong) SPTexture *downState

Discussion

The texture that is displayed while the button is touched.

Declared In

SPButton.h

enabled

Indicates if the button can be triggered.

@property (nonatomic, assign) BOOL enabled

Discussion

Indicates if the button can be triggered.

Declared In

SPButton.h

fontColor

The color of the font.

@property (nonatomic, assign) uint fontColor

Discussion

The color of the font.

Declared In

SPButton.h

fontName

The name of the font displayed on the button. May be a system font or a registered bitmap font.

@property (nonatomic, copy) NSString *fontName

Discussion

The name of the font displayed on the button. May be a system font or a registered bitmap font.

Declared In

SPButton.h

fontSize

The size of the font.

@property (nonatomic, assign) float fontSize

Discussion

The size of the font.

Declared In

SPButton.h

isDown

Indicates if the button is currently being pressed.

@property (nonatomic, readonly) BOOL isDown

Discussion

Indicates if the button is currently being pressed.

Declared In

SPButton.h

scaleWhenDown

The scale factor of the button on touch. Per default, a button with a down state texture won’t scale.

@property (nonatomic, assign) float scaleWhenDown

Discussion

The scale factor of the button on touch. Per default, a button with a down state texture won’t scale.

Declared In

SPButton.h

text

The text that is displayed on the button.

@property (nonatomic, copy) NSString *text

Discussion

The text that is displayed on the button.

Declared In

SPButton.h

textBounds

The bounds of the textfield on the button. Allows moving the text to a custom position.

@property (nonatomic, copy) SPRectangle *textBounds

Discussion

The bounds of the textfield on the button. Allows moving the text to a custom position.

Declared In

SPButton.h

upState

The texture that is displayed when the button is not being touched.

@property (nonatomic, strong) SPTexture *upState

Discussion

The texture that is displayed when the button is not being touched.

Declared In

SPButton.h

Class Methods

buttonWithUpState:

Factory method.

+ (instancetype)buttonWithUpState:(SPTexture *)upState

Discussion

Factory method.

Declared In

SPButton.h

buttonWithUpState:downState:

Factory method.

+ (instancetype)buttonWithUpState:(SPTexture *)upState downState:(SPTexture *)downState

Discussion

Factory method.

Declared In

SPButton.h

buttonWithUpState:text:

Factory method.

+ (instancetype)buttonWithUpState:(SPTexture *)upState text:(NSString *)text

Discussion

Factory method.

Declared In

SPButton.h

Instance Methods

initWithUpState:

Initializes a button only with an up state.

- (instancetype)initWithUpState:(SPTexture *)upState

Discussion

Initializes a button only with an up state.

Declared In

SPButton.h

initWithUpState:downState:

Initializes a button with textures for up- and down-state. Designated Initializer.

- (instancetype)initWithUpState:(SPTexture *)upState downState:(SPTexture *)downState

Discussion

Initializes a button with textures for up- and down-state. Designated Initializer.

Declared In

SPButton.h

initWithUpState:text:

Initializes a button with an up state texture and text.

- (instancetype)initWithUpState:(SPTexture *)upState text:(NSString *)text

Discussion

Initializes a button with an up state texture and text.

Declared In

SPButton.h