// // UIButton+RQExtension.h // XinShouJiaDao // // Created by 张嵘 on 2021/7/7. // Copyright © 2021 JCZ. All rights reserved. // #import NS_ASSUME_NONNULL_BEGIN typedef void (^TouchedBlock)(NSInteger tag); // 定义一个枚举(包含了四种类型的button) typedef NS_ENUM(NSUInteger, RQButtonEdgeInsetsStyle) { RQButtonEdgeInsetsStyleTop, // image在上,label在下 RQButtonEdgeInsetsStyleLeft, // image在左,label在右 RQButtonEdgeInsetsStyleBottom, // image在下,label在上 RQButtonEdgeInsetsStyleRight // image在右,label在左 }; @interface UIButton (RQExtension) @property (nonatomic)IBInspectable float fixWidthScreenFont; /** 添加 addtarget */ - (void)addActionHandler:(TouchedBlock)touchHandler; /** * @brief 使用颜色设置按钮背景 * * @param backgroundColor 背景颜色 * @param state 按钮状态 */ - (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state; /* * @brief * * @param frame frame * @param buttonTitle 标题 * @param normalBGColor 未选中的背景色 * @param selectBGColor 选中的背景色 * @param normalColor 未选中的文字色 * @param selectColor 选中的文字色 * @param buttonFont 文字字体 * @param cornerRadius 圆角值 没有则为0 * @param doneBlock 点击事件 * * @return */ - (instancetype)initWithFrame:(CGRect)frame buttonTitle:(NSString *)buttonTitle normalBGColor:(UIColor *)normalBGColor selectBGColor:(nullable UIColor *)selectBGColor normalColor:(UIColor *)normalColor selectColor:(nullable UIColor *)selectColor buttonFont:(UIFont *)buttonFont cornerRadius:(CGFloat )cornerRadius doneBlock:(void(^)(UIButton *))doneBlock; + (UIButton *)initWithFrame:(CGRect)frame buttonTitle:(NSString *)buttonTitle normalBGColor:(UIColor *)normalBGColor selectBGColor:(UIColor *)selectBGColor normalColor:(UIColor *)normalColor selectColor:(UIColor *)selectColor buttonFont:(UIFont *)buttonFont cornerRadius:(CGFloat )cornerRadius doneBlock:(void(^)(UIButton *))doneBlock; /**默认的字体大小 */ - (void)setImage:(UIImage *)image withTitle:(NSString *)title forState:(UIControlState)stateType; - (void)setImage:(UIImage *)image withTitle:(NSString *)title Font:(CGFloat)font forState:(UIControlState)stateType; - (void)setTitle:(NSString*)title textColor:(UIColor*)color Font:(CGFloat)font fotState:(UIControlState)stateType; - (void)setImage:(UIImage *)image withTitle:(NSString*)title textColor:(UIColor*)color Font:(CGFloat)font fotState:(UIControlState)stateType; /**简化按钮事件添加。要求一定要实现btnClick; */ -(void)target:(id)obj; -(void)target:(id)obj tag:(NSInteger)tag; -(void)setTitleNormal:(NSString*)title; -(void)setTitleSelect:(NSString*)title; /** * 设置button的titleLabel和imageView的布局样式,及间距 * * @param style titleLabel和imageView的布局样式 * @param space titleLabel和imageView的间距 */ - (void)layoutButtonWithEdgeInsetsStyle:(RQButtonEdgeInsetsStyle)style imageTitleSpace:(CGFloat)space; @end NS_ASSUME_NONNULL_END