Class UIButton

All Implemented Interfaces:
CALayerDelegate, NSCoding, NSObjectProtocol, UIAccessibilityContentSizeCategoryImageAdjusting, UIAccessibilityIdentification, UIActivityItemsConfigurationProviding, UIAppearanceContainer, UIContextMenuInteractionDelegate, UICoordinateSpace, UIDynamicItem, UIFocusEnvironment, UIFocusItem, UIFocusItemContainer, UILargeContentViewerItem, UIPasteConfigurationSupporting, UIResponderStandardEditActions, UISpringLoadedInteractionSupporting, UITraitEnvironment, UIUserActivityRestoring, ObjCProtocol
Direct Known Subclasses:
INUIAddVoiceShortcutButton, PKAddPassButton, PKPaymentButton

public class UIButton
extends UIControl
implements NSCoding, UISpringLoadedInteractionSupporting, UIAccessibilityContentSizeCategoryImageAdjusting
  • Constructor Details

    • UIButton

      public UIButton()
    • UIButton

      protected UIButton​(NSObject.Handle h, long handle)
    • UIButton

      protected UIButton​(NSObject.SkipInit skipInit)
    • UIButton

      public UIButton​(CGRect frame)
    • UIButton

      public UIButton​(NSCoder coder)
    • UIButton

      public UIButton​(CGRect frame, UIAction primaryAction)
      Since:
      Available in iOS 14.0 and later.
    • UIButton

      public UIButton​(UIButtonType buttonType)
    • UIButton

      public UIButton​(UIButtonType buttonType, UIAction primaryAction)
      Since:
      Available in iOS 14.0 and later.
    • UIButton

      public UIButton​(UIButtonConfiguration configuration, UIAction primaryAction)
      Since:
      Available in iOS 15.0 and later.
  • Method Details

    • getConfiguration

      public UIButtonConfiguration getConfiguration()
      Since:
      Available in iOS 15.0 and later.
    • setConfiguration

      public void setConfiguration​(UIButtonConfiguration v)
      Since:
      Available in iOS 15.0 and later.
    • getConfigurationUpdateHandler

      public VoidBlock1<UIButton> getConfigurationUpdateHandler()
      Since:
      Available in iOS 15.0 and later.
    • setConfigurationUpdateHandler

      public void setConfigurationUpdateHandler​(VoidBlock1<UIButton> v)
      Since:
      Available in iOS 15.0 and later.
    • automaticallyUpdatesConfiguration

      public boolean automaticallyUpdatesConfiguration()
      Since:
      Available in iOS 15.0 and later.
    • setAutomaticallyUpdatesConfiguration

      public void setAutomaticallyUpdatesConfiguration​(boolean v)
      Since:
      Available in iOS 15.0 and later.
    • getTintColor

      public UIColor getTintColor()
      Overrides:
      getTintColor in class UIView
    • setTintColor

      public void setTintColor​(UIColor v)
      Overrides:
      setTintColor in class UIView
    • getButtonType

      public UIButtonType getButtonType()
    • isHovered

      public boolean isHovered()
      Since:
      Available in iOS 15.0 and later.
    • isHeld

      public boolean isHeld()
      Since:
      Available in iOS 15.0 and later.
    • getRole

      public UIButtonRole getRole()
      Since:
      Available in iOS 14.0 and later.
    • setRole

      public void setRole​(UIButtonRole v)
      Since:
      Available in iOS 14.0 and later.
    • isPointerInteractionEnabled

      public boolean isPointerInteractionEnabled()
      Since:
      Available in iOS 13.4 and later.
    • setPointerInteractionEnabled

      public void setPointerInteractionEnabled​(boolean v)
      Since:
      Available in iOS 13.4 and later.
    • getPointerStyleProvider

      public Block3<UIButton,​UIPointerEffect,​UIPointerShape,​UIPointerStyle> getPointerStyleProvider()
      Since:
      Available in iOS 13.4 and later.
    • setPointerStyleProvider

      public void setPointerStyleProvider​(Block3<UIButton,​UIPointerEffect,​UIPointerShape,​UIPointerStyle> v)
      Since:
      Available in iOS 13.4 and later.
    • getMenu

      public UIMenu getMenu()
      Since:
      Available in iOS 14.0 and later.
    • setMenu

      public void setMenu​(UIMenu v)
      Since:
      Available in iOS 14.0 and later.
    • isChangesSelectionAsPrimaryAction

      public boolean isChangesSelectionAsPrimaryAction()
      Since:
      Available in iOS 15.0 and later.
    • setChangesSelectionAsPrimaryAction

      public void setChangesSelectionAsPrimaryAction​(boolean v)
      Since:
      Available in iOS 15.0 and later.
    • getCurrentTitle

      public String getCurrentTitle()
    • getCurrentTitleColor

      public UIColor getCurrentTitleColor()
    • getCurrentTitleShadowColor

      public UIColor getCurrentTitleShadowColor()
    • getCurrentImage

      public UIImage getCurrentImage()
    • getCurrentBackgroundImage

      public UIImage getCurrentBackgroundImage()
    • getCurrentPreferredSymbolConfiguration

      public UIImageSymbolConfiguration getCurrentPreferredSymbolConfiguration()
      Since:
      Available in iOS 13.0 and later.
    • getCurrentAttributedTitle

      public NSAttributedString getCurrentAttributedTitle()
    • getTitleLabel

      public UILabel getTitleLabel()
    • getImageView

      public UIImageView getImageView()
    • getSubtitleLabel

      public UILabel getSubtitleLabel()
      Since:
      Available in iOS 15.0 and later.
    • getLayerClass

      public static Class<? extends CALayer> getLayerClass()
    • getContentEdgeInsets

      @Deprecated public UIEdgeInsets getContentEdgeInsets()
      Deprecated.
      Deprecated in iOS 15.0. This property is ignored when using UIButtonConfiguration
    • setContentEdgeInsets

      @Deprecated public void setContentEdgeInsets​(UIEdgeInsets v)
      Deprecated.
      Deprecated in iOS 15.0. This property is ignored when using UIButtonConfiguration
    • getTitleEdgeInsets

      @Deprecated public UIEdgeInsets getTitleEdgeInsets()
      Deprecated.
      Deprecated in iOS 15.0. This property is ignored when using UIButtonConfiguration
    • setTitleEdgeInsets

      @Deprecated public void setTitleEdgeInsets​(UIEdgeInsets v)
      Deprecated.
      Deprecated in iOS 15.0. This property is ignored when using UIButtonConfiguration
    • getImageEdgeInsets

      @Deprecated public UIEdgeInsets getImageEdgeInsets()
      Deprecated.
      Deprecated in iOS 15.0. This property is ignored when using UIButtonConfiguration
    • setImageEdgeInsets

      @Deprecated public void setImageEdgeInsets​(UIEdgeInsets v)
      Deprecated.
      Deprecated in iOS 15.0. This property is ignored when using UIButtonConfiguration
    • reversesTitleShadowWhenHighlighted

      @Deprecated public boolean reversesTitleShadowWhenHighlighted()
      Deprecated.
      Deprecated in iOS 15.0. This property is ignored when using UIButtonConfiguration, you may customize to replicate this behavior via a configurationUpdateHandler
    • setReversesTitleShadowWhenHighlighted

      @Deprecated public void setReversesTitleShadowWhenHighlighted​(boolean v)
      Deprecated.
      Deprecated in iOS 15.0. This property is ignored when using UIButtonConfiguration, you may customize to replicate this behavior via a configurationUpdateHandler
    • adjustsImageWhenHighlighted

      @Deprecated public boolean adjustsImageWhenHighlighted()
      Deprecated.
      Deprecated in iOS 15.0. This property is ignored when using UIButtonConfiguration, you may customize to replicate this behavior via a configurationUpdateHandler
    • setAdjustsImageWhenHighlighted

      @Deprecated public void setAdjustsImageWhenHighlighted​(boolean v)
      Deprecated.
      Deprecated in iOS 15.0. This property is ignored when using UIButtonConfiguration, you may customize to replicate this behavior via a configurationUpdateHandler
    • adjustsImageWhenDisabled

      @Deprecated public boolean adjustsImageWhenDisabled()
      Deprecated.
      Deprecated in iOS 15.0. This property is ignored when using UIButtonConfiguration, you may customize to replicate this behavior via a configurationUpdateHandler
    • setAdjustsImageWhenDisabled

      @Deprecated public void setAdjustsImageWhenDisabled​(boolean v)
      Deprecated.
      Deprecated in iOS 15.0. This property is ignored when using UIButtonConfiguration, you may customize to replicate this behavior via a configurationUpdateHandler
    • showsTouchWhenHighlighted

      @Deprecated public boolean showsTouchWhenHighlighted()
      Deprecated.
      Deprecated in iOS 15.0. This property is ignored when using UIButtonConfiguration
    • setShowsTouchWhenHighlighted

      @Deprecated public void setShowsTouchWhenHighlighted​(boolean v)
      Deprecated.
      Deprecated in iOS 15.0. This property is ignored when using UIButtonConfiguration
    • getBehavioralStyle

      public UIBehavioralStyle getBehavioralStyle()
      Since:
      Available in iOS 15.0 and later.
    • getPreferredBehavioralStyle

      public UIBehavioralStyle getPreferredBehavioralStyle()
      Since:
      Available in iOS 15.0 and later.
    • setPreferredBehavioralStyle

      public void setPreferredBehavioralStyle​(UIBehavioralStyle v)
      Since:
      Available in iOS 15.0 and later.
    • isSpringLoaded

      public boolean isSpringLoaded()
      Specified by:
      isSpringLoaded in interface UISpringLoadedInteractionSupporting
      Since:
      Available in iOS 11.0 and later.
    • setSpringLoaded

      public void setSpringLoaded​(boolean v)
      Specified by:
      setSpringLoaded in interface UISpringLoadedInteractionSupporting
      Since:
      Available in iOS 11.0 and later.
    • adjustsImageSizeForAccessibilityContentSizeCategory

      public boolean adjustsImageSizeForAccessibilityContentSizeCategory()
      Specified by:
      adjustsImageSizeForAccessibilityContentSizeCategory in interface UIAccessibilityContentSizeCategoryImageAdjusting
    • setAdjustsImageSizeForAccessibilityContentSizeCategory

      public void setAdjustsImageSizeForAccessibilityContentSizeCategory​(boolean v)
      Specified by:
      setAdjustsImageSizeForAccessibilityContentSizeCategory in interface UIAccessibilityContentSizeCategoryImageAdjusting
    • init

      protected long init​(CGRect frame)
      Overrides:
      init in class UIControl
    • init

      protected long init​(NSCoder coder)
      Overrides:
      init in class UIControl
    • init

      protected long init​(CGRect frame, UIAction primaryAction)
      Overrides:
      init in class UIControl
      Since:
      Available in iOS 14.0 and later.
    • setNeedsUpdateConfiguration

      public void setNeedsUpdateConfiguration()
      Since:
      Available in iOS 15.0 and later.
    • updateConfiguration

      public void updateConfiguration()
      Since:
      Available in iOS 15.0 and later.
    • setTitle

      public void setTitle​(String title, UIControlState state)
    • setTitleColor

      public void setTitleColor​(UIColor color, UIControlState state)
    • setTitleShadowColor

      public void setTitleShadowColor​(UIColor color, UIControlState state)
    • setImage

      public void setImage​(UIImage image, UIControlState state)
    • setBackgroundImage

      public void setBackgroundImage​(UIImage image, UIControlState state)
    • setPreferredSymbolConfiguration

      public void setPreferredSymbolConfiguration​(UIImageSymbolConfiguration configuration, UIControlState state)
      Since:
      Available in iOS 13.0 and later.
    • setAttributedTitle

      public void setAttributedTitle​(NSAttributedString title, UIControlState state)
    • getTitle

      public String getTitle​(UIControlState state)
    • getTitleColor

      public UIColor getTitleColor​(UIControlState state)
    • getTitleShadowColor

      public UIColor getTitleShadowColor​(UIControlState state)
    • getImage

      public UIImage getImage​(UIControlState state)
    • getBackgroundImage

      public UIImage getBackgroundImage​(UIControlState state)
    • preferredSymbolConfigurationForImageInState

      public UIImageSymbolConfiguration preferredSymbolConfigurationForImageInState​(UIControlState state)
      Since:
      Available in iOS 13.0 and later.
    • getAttributedTitle

      public NSAttributedString getAttributedTitle​(UIControlState state)
    • create0

      protected static long create0​(UIButtonType buttonType)
    • getSystemButtonWithImage

      public static UIButton getSystemButtonWithImage​(UIImage image, NSObject target, Selector action)
      Since:
      Available in iOS 13.0 and later.
    • getSystemButtonWithPrimaryAction

      public static UIButton getSystemButtonWithPrimaryAction​(UIAction primaryAction)
      Since:
      Available in iOS 14.0 and later.
    • create0

      protected static long create0​(UIButtonType buttonType, UIAction primaryAction)
      Since:
      Available in iOS 14.0 and later.
    • create

      protected static long create​(UIButtonConfiguration configuration, UIAction primaryAction)
      Since:
      Available in iOS 15.0 and later.
    • getUserInterfaceLayoutDirection

      public static UIUserInterfaceLayoutDirection getUserInterfaceLayoutDirection​(UISemanticContentAttribute attribute)
      Since:
      Available in iOS 9.0 and later.
    • getUserInterfaceLayoutDirection

      public static UIUserInterfaceLayoutDirection getUserInterfaceLayoutDirection​(UISemanticContentAttribute semanticContentAttribute, UIUserInterfaceLayoutDirection layoutDirection)
      Since:
      Available in iOS 10.0 and later.
    • getBackgroundRect

      @Deprecated public CGRect getBackgroundRect​(CGRect bounds)
      Deprecated.
      Deprecated in iOS 15.0. Override layoutSubviews, call super, and position views as you desire.
    • getContentRect

      @Deprecated public CGRect getContentRect​(CGRect bounds)
      Deprecated.
      Deprecated in iOS 15.0. Override layoutSubviews, call super, and position views as you desire.
    • getTitleRect

      @Deprecated public CGRect getTitleRect​(CGRect contentRect)
      Deprecated.
      Deprecated in iOS 15.0. Override layoutSubviews, call super, and position views as you desire.
    • getImageRect

      @Deprecated public CGRect getImageRect​(CGRect contentRect)
      Deprecated.
      Deprecated in iOS 15.0. Override layoutSubviews, call super, and position views as you desire.