UIButton(FWUIKit)

@interface UIButton (FWUIKit)

/// 全局自定义按钮高亮时的alpha配置,默认0.5
@property (class, nonatomic, assign) CGFloat fw_highlightedAlpha NS_REFINED_FOR_SWIFT;
    
/// 全局自定义按钮禁用时的alpha配置,默认0.3
@property (class, nonatomic, assign) CGFloat fw_disabledAlpha NS_REFINED_FOR_SWIFT;

/// 自定义按钮禁用时的alpha,如0.3,默认0不生效
@property (nonatomic, assign) CGFloat fw_disabledAlpha NS_REFINED_FOR_SWIFT;

/// 自定义按钮高亮时的alpha,如0.5,默认0不生效
@property (nonatomic, assign) CGFloat fw_highlightedAlpha NS_REFINED_FOR_SWIFT;

/// 自定义按钮禁用状态改变时的句柄,默认nil
@property (nonatomic, copy, nullable) void (^fw_disabledChanged)(UIButton *button, BOOL disabled) NS_REFINED_FOR_SWIFT;

/// 自定义按钮高亮状态改变时的句柄,默认nil
@property (nonatomic, copy, nullable) void (^fw_highlightedChanged)(UIButton *button, BOOL highlighted) NS_REFINED_FOR_SWIFT;

/// 快速设置文本按钮
- (void)fw_setTitle:(nullable NSString *)title font:(nullable UIFont *)font titleColor:(nullable UIColor *)titleColor NS_REFINED_FOR_SWIFT;

/// 快速设置文本
- (void)fw_setTitle:(nullable NSString *)title NS_REFINED_FOR_SWIFT;

/// 快速设置图片
- (void)fw_setImage:(nullable UIImage *)image NS_REFINED_FOR_SWIFT;

/// 设置图片的居中边位置,需要在setImage和setTitle之后调用才生效,且button大小大于图片+文字+间距
///
/// imageEdgeInsets: 仅有image时相对于button,都有时上左下相对于button,右相对于title
/// titleEdgeInsets: 仅有title时相对于button,都有时上右下相对于button,左相对于image
- (void)fw_setImageEdge:(UIRectEdge)edge spacing:(CGFloat)spacing NS_REFINED_FOR_SWIFT;

/// 设置状态背景色
- (void)fw_setBackgroundColor:(nullable UIColor *)backgroundColor forState:(UIControlState)state NS_REFINED_FOR_SWIFT;

/// 快速创建文本按钮
+ (instancetype)fw_buttonWithTitle:(nullable NSString *)title font:(nullable UIFont *)font titleColor:(nullable UIColor *)titleColor NS_REFINED_FOR_SWIFT;

/// 快速创建图片按钮
+ (instancetype)fw_buttonWithImage:(nullable UIImage *)image NS_REFINED_FOR_SWIFT;

/// 开始按钮倒计时,从window移除时自动取消。等待时按钮disabled,非等待时enabled。时间支持格式化,示例:重新获取(%lds)
- (dispatch_source_t)fw_startCountDown:(NSInteger)seconds title:(NSString *)title waitTitle:(NSString *)waitTitle NS_REFINED_FOR_SWIFT;

@end

Undocumented

  • 全局自定义按钮高亮时的alpha配置,默认0.5

    Declaration

    Objective-C

    @property (class, nonatomic) CGFloat fw_highlightedAlpha;
  • 全局自定义按钮禁用时的alpha配置,默认0.3

    Declaration

    Objective-C

    @property (class, nonatomic) CGFloat fw_disabledAlpha;
  • 自定义按钮禁用时的alpha,如0.3,默认0不生效

    Declaration

    Objective-C

    @property (nonatomic) CGFloat fw_disabledAlpha;
  • 自定义按钮高亮时的alpha,如0.5,默认0不生效

    Declaration

    Objective-C

    @property (nonatomic) CGFloat fw_highlightedAlpha;
  • 自定义按钮禁用状态改变时的句柄,默认nil

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) void (^) (UIButton *_Nonnull __strong, BOOL) fw_disabledChanged;
  • 自定义按钮高亮状态改变时的句柄,默认nil

    Declaration

    Objective-C

    @property (nonatomic, copy, nullable) void (^) (UIButton *_Nonnull __strong, BOOL) fw_highlightedChanged;
  • 快速设置文本按钮

    Declaration

    Objective-C

    - (void)fw_setTitle:(nullable NSString *)title
                   font:(nullable UIFont *)font
             titleColor:(nullable UIColor *)titleColor;
  • 快速设置文本

    Declaration

    Objective-C

    - (void)fw_setTitle:(nullable NSString *)title;
  • 快速设置图片

    Declaration

    Objective-C

    - (void)fw_setImage:(nullable UIImage *)image;
  • 设置图片的居中边位置,需要在setImage和setTitle之后调用才生效,且button大小大于图片+文字+间距

    imageEdgeInsets: 仅有image时相对于button,都有时上左下相对于button,右相对于title titleEdgeInsets: 仅有title时相对于button,都有时上右下相对于button,左相对于image

    Declaration

    Objective-C

    - (void)fw_setImageEdge:(UIRectEdge)edge spacing:(CGFloat)spacing;
  • 设置状态背景色

    Declaration

    Objective-C

    - (void)fw_setBackgroundColor:(nullable UIColor *)backgroundColor
                         forState:(UIControlState)state;
  • 快速创建文本按钮

    Declaration

    Objective-C

    + (nonnull instancetype)fw_buttonWithTitle:(nullable NSString *)title
                                          font:(nullable UIFont *)font
                                    titleColor:(nullable UIColor *)titleColor;
  • 快速创建图片按钮

    Declaration

    Objective-C

    + (nonnull instancetype)fw_buttonWithImage:(nullable UIImage *)image;
  • 开始按钮倒计时,从window移除时自动取消。等待时按钮disabled,非等待时enabled。时间支持格式化,示例:重新获取(%lds)

    Declaration

    Objective-C

    - (nonnull dispatch_source_t)fw_startCountDown:(NSInteger)seconds
                                             title:(nonnull NSString *)title
                                         waitTitle:(nonnull NSString *)waitTitle;