MDCButton

@interface MDCButton : UIButton <MDCElevatable, MDCElevationOverriding>

A Material flat, raised or floating button.

All buttons display animated ink splashes when the user interacts with the button.

The title color of the button set to have an accessible contrast ratio with the button’s background color. To ensure this works for flat buttons (with transparent background), the caller is responsible for setting (and updating, if necessary) the button’s underlyingColor property.

All buttons set the exclusiveTouch property to YES by default, which prevents users from simultaneously interacting with a button and other UI elements.

  • The ink style of the button.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) MDCInkStyle inkStyle;
  • The ink color of the button.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, null_resettable) UIColor *inkColor;
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, assign) CGFloat inkMaxRippleRadius
  • This property determines if an @c MDCButton should use the @c MDCInkView behavior or not.

    By setting this property to @c YES, @c MDCStatefulRippleView is used to provide the user visual touch feedback, instead of the legacy @c MDCInkView.

    Note

    Defaults to @c NO.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL enableRippleBehavior;
  • The alpha value that will be applied when the button is disabled. Most clients can leave this as the default value to get a semi-transparent button automatically.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CGFloat disabledAlpha;
  • If true, converts the button title to uppercase. Changing this property to NO will update the current title string.

    Default is YES.

    Declaration

    Objective-C

    @property (getter=isUppercaseTitle, assign, readwrite, nonatomic)
        BOOL uppercaseTitle;
  • Insets to apply to the button’s hit area.

    Allows the button to detect touches outside of its bounds. A negative value indicates an extension past the bounds.

    Default is UIEdgeInsetsZero.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) UIEdgeInsets hitAreaInsets;
  • The minimum size of the button’s alignment rect. If either the height or width are non-positive (negative or zero), they will be ignored and that axis will adjust to its content size.

    Defaults to CGSizeZero.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CGSize minimumSize;
  • The maximum size of the button’s alignment rect. If either the height or width are non-positive (negative or zero), they will be ignored and that axis will adjust to its content size. Setting a maximum size may result in image clipping or text truncation.

    Defaults to CGSizeZero.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) CGSize maximumSize;
  • The apparent background color as seen by the user, i.e. the color of the view behind the button.

    The underlying color hint is used by buttons to calculate accessible title text colors when in states with transparent background colors. The hint is used whenever the button changes state such that the background color changes, for example, setting the background color or disabling the button.

    For flat buttons, this is the color of both the surrounding area and the button’s background. For raised and floating buttons, this is the color of view underneath the button.

    The default is nil. If left unset, buttons will likely have an incorrect appearance when disabled. Additionally, flat buttons might have text colors with low accessibility.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIColor *underlyingColorHint;
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, readwrite, setter=mdc_setAdjustsFontForContentSizeCategory:)
        BOOL mdc_adjustsFontForContentSizeCategory
  • Affects the fallback behavior for when a scaled font is not provided.

    If @c YES, the font size will adjust even if a scaled font has not been provided for a given @c UIFont property on this component.

    If @c NO, the font size will only be adjusted if a scaled font has been provided.

    Default value is @c YES.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic)
        BOOL adjustsFontForContentSizeCategoryWhenScaledFontIsUnavailable;
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, readwrite, setter=mdc_setLegacyFontScaling:)
        BOOL mdc_legacyFontScaling
  • The shape generator used to define the button’s shape.

    note: If a layer property is explicitly set after the shapeGenerator has been set, it can lead to unexpected behavior.

    When the shapeGenerator is nil, MDCButton will use the default underlying layer with its default settings.

    Default value for shapeGenerator is nil.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) id<MDCShapeGenerating>
        shapeGenerator;
  • If true, @c accessiblityTraits will always include @c UIAccessibilityTraitButton.

    Note

    Defaults to true.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic) BOOL accessibilityTraitsIncludesButton;
  • A block that is invoked when the MDCButton receives a call to @c traitCollectionDidChange:. The block is called after the call to the superclass.

    Declaration

    Objective-C

    @property (readwrite, copy, nonatomic, nullable) void (^)
        (MDCButton *_Nonnull, UITraitCollection *_Nullable)
            traitCollectionDidChangeBlock;
  • A color used as the button’s @c backgroundColor for @c state.

    Declaration

    Objective-C

    - (nullable UIColor *)backgroundColorForState:(UIControlState)state;

    Parameters

    state

    The state.

    Return Value

    The background color.

  • A color used as the button’s @c backgroundColor.

    If left unset or reset to nil for a given state, then a default blue color is used.

    Declaration

    Objective-C

    - (void)setBackgroundColor:(nullable UIColor *)backgroundColor
                      forState:(UIControlState)state;

    Parameters

    backgroundColor

    The background color.

    state

    The state.

  • Undocumented

    Declaration

    Objective-C

    - (void)setBackgroundColor:(nullable UIColor *)backgroundColor;
  • The font used by the button’s @c title for @c state.

    Declaration

    Objective-C

    - (nullable UIFont *)titleFontForState:(UIControlState)state;

    Parameters

    state

    The state.

    Return Value

    The font.

  • The font used by the button’s @c title.

    If left unset or reset to nil for a given state, then a default font is used.

    Declaration

    Objective-C

    - (void)setTitleFont:(nullable UIFont *)font forState:(UIControlState)state;

    Parameters

    font

    The font.

    state

    The state.

  • Sets the enabled state with optional animation.

    Declaration

    Objective-C

    - (void)setEnabled:(BOOL)enabled animated:(BOOL)animated;
  • Returns the elevation for a particular control state.

    The default values depend on the kind of button, for example, flat buttons in the UIControlStateNormal state have zero elevation.

    Declaration

    Objective-C

    - (MDCShadowElevation)elevationForState:(UIControlState)state;

    Parameters

    state

    The control state to retrieve the elevation.

    Return Value

    The elevation for the requested state.

  • Sets the elevation for a particular control state.

    Declaration

    Objective-C

    - (void)setElevation:(MDCShadowElevation)elevation
                forState:(UIControlState)state;

    Parameters

    elevation

    The elevation to set.

    state

    The state to set.

  • A color used as the button’s @c borderColor for @c state.

    Declaration

    Objective-C

    - (nullable UIColor *)borderColorForState:(UIControlState)state;

    Parameters

    state

    The state.

    Return Value

    The border color.

  • Sets the border color for a particular control state. Sets the @c borderColor of the layer.

    Declaration

    Objective-C

    - (void)setBorderColor:(nullable UIColor *)borderColor
                  forState:(UIControlState)state;

    Parameters

    borderColor

    The border color to set.

    state

    The state to set.

  • A color used as the button’s imageView tint color @c imageTintColor for @c state.

    If no image tint color has been set for a given state, the returned value will fall back to the value set for UIControlStateNormal.

    Declaration

    Objective-C

    - (nullable UIColor *)imageTintColorForState:(UIControlState)state;

    Parameters

    state

    The state.

    Return Value

    The tint color.

  • Sets the image view tint color for a particular control state.

    If left unset or reset to nil for a given state, it falls back to UIControlStateNormal setting.

    Declaration

    Objective-C

    - (void)setImageTintColor:(nullable UIColor *)imageTintColor
                     forState:(UIControlState)state;

    Parameters

    imageTintColor

    The imageView tint color to set.

    state

    The state to set.

  • The value set for the button’s @c borderWidth for @c state.

    Declaration

    Objective-C

    - (CGFloat)borderWidthForState:(UIControlState)state;

    Parameters

    state

    The state.

    Return Value

    The border width.

  • Sets the border width for a particular control state. Sets the @c borderWidth of the layer.

    Declaration

    Objective-C

    - (void)setBorderWidth:(CGFloat)borderWidth forState:(UIControlState)state;

    Parameters

    borderWidth

    The border width to set.

    state

    The state to set.

  • Sets this button’s layer’s shadowColor for the specified control state.

    During initialization, the value for @c UIControlStateNormal is set to the value of this button’s layer’s @c shadowColor. Providing a @c nil value for @c shadowColor will remove the shadow color mapping for the specified state.

    If the color is not set for a specified state, the default behavior is to use the color associated with @c UIControlStateNormal. If the color for @c UIControlStateNormal is not set, then @c nil will be used.

    Declaration

    Objective-C

    - (void)setShadowColor:(nullable UIColor *)shadowColor
                  forState:(UIControlState)state;

    Parameters

    shadowColor

    The shadow color to use for the specified state.

    state

    The state that uses the specified color. The possible values are described in @c UIControlState.

  • The color used as this button’s layer’s @c shadowColor for the specified control state.

    During initialization, the value for @c UIControlStateNormal is set to the value of this view’s layer’s @c shadowColor.

    If the color is not set for a specified state, the default behavior is to use the color associated with @c UIControlStateNormal. If the color for @c UIControlStateNormal has not been set, then @c nil is returned.

    Declaration

    Objective-C

    - (nullable UIColor *)shadowColorForState:(UIControlState)state;

    Parameters

    state

    The state that uses the shadow color. The possible values are described in @c UIControlState.

    Return Value

    The shadow color.

  • From UIButton’s documentation: 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.

    Declaration

    Objective-C

    + (nonnull instancetype)buttonWithType:(UIButtonType)buttonType;
  • This property sets/gets the title color for UIControlStateNormal.

    Declaration

    Objective-C

    @property (readwrite, strong, nonatomic, nullable) UIColor *customTitleColor;
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic)
        BOOL shouldRaiseOnTouch
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic) BOOL shouldCapitalizeTitle
  • Undocumented

    Declaration

    Objective-C

    @property(nonatomic, strong, nullable)
        UIColor *underlyingColor