UIButton+RQExtension.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // UIButton+RQExtension.h
  3. // XinShouJiaDao
  4. //
  5. // Created by 张嵘 on 2021/7/7.
  6. // Copyright © 2021 JCZ. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. NS_ASSUME_NONNULL_BEGIN
  10. typedef void (^TouchedBlock)(NSInteger tag);
  11. // 定义一个枚举(包含了四种类型的button)
  12. typedef NS_ENUM(NSUInteger, RQButtonEdgeInsetsStyle) {
  13. RQButtonEdgeInsetsStyleTop, // image在上,label在下
  14. RQButtonEdgeInsetsStyleLeft, // image在左,label在右
  15. RQButtonEdgeInsetsStyleBottom, // image在下,label在上
  16. RQButtonEdgeInsetsStyleRight // image在右,label在左
  17. };
  18. @interface UIButton (RQExtension)
  19. @property (nonatomic)IBInspectable float fixWidthScreenFont;
  20. /**
  21. 添加 addtarget
  22. */
  23. - (void)addActionHandler:(TouchedBlock)touchHandler;
  24. /**
  25. * @brief 使用颜色设置按钮背景
  26. *
  27. * @param backgroundColor 背景颜色
  28. * @param state 按钮状态
  29. */
  30. - (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state;
  31. /*
  32. * @brief
  33. *
  34. * @param frame frame
  35. * @param buttonTitle 标题
  36. * @param normalBGColor 未选中的背景色
  37. * @param selectBGColor 选中的背景色
  38. * @param normalColor 未选中的文字色
  39. * @param selectColor 选中的文字色
  40. * @param buttonFont 文字字体
  41. * @param cornerRadius 圆角值 没有则为0
  42. * @param doneBlock 点击事件
  43. *
  44. * @return
  45. */
  46. - (instancetype)initWithFrame:(CGRect)frame buttonTitle:(NSString *)buttonTitle normalBGColor:(UIColor *)normalBGColor selectBGColor:(nullable UIColor *)selectBGColor
  47. normalColor:(UIColor *)normalColor selectColor:(nullable UIColor *)selectColor buttonFont:(UIFont *)buttonFont cornerRadius:(CGFloat )cornerRadius
  48. doneBlock:(void(^)(UIButton *))doneBlock;
  49. + (UIButton *)initWithFrame:(CGRect)frame buttonTitle:(NSString *)buttonTitle normalBGColor:(UIColor *)normalBGColor selectBGColor:(UIColor *)selectBGColor
  50. normalColor:(UIColor *)normalColor selectColor:(UIColor *)selectColor buttonFont:(UIFont *)buttonFont cornerRadius:(CGFloat )cornerRadius
  51. doneBlock:(void(^)(UIButton *))doneBlock;
  52. /**默认的字体大小
  53. */
  54. - (void)setImage:(UIImage *)image withTitle:(NSString *)title forState:(UIControlState)stateType;
  55. - (void)setImage:(UIImage *)image withTitle:(NSString *)title Font:(CGFloat)font forState:(UIControlState)stateType;
  56. - (void)setTitle:(NSString*)title textColor:(UIColor*)color Font:(CGFloat)font fotState:(UIControlState)stateType;
  57. - (void)setImage:(UIImage *)image withTitle:(NSString*)title textColor:(UIColor*)color Font:(CGFloat)font fotState:(UIControlState)stateType;
  58. /**简化按钮事件添加。要求一定要实现btnClick;
  59. */
  60. -(void)target:(id)obj;
  61. -(void)target:(id)obj tag:(NSInteger)tag;
  62. -(void)setTitleNormal:(NSString*)title;
  63. -(void)setTitleSelect:(NSString*)title;
  64. /**
  65. * 设置button的titleLabel和imageView的布局样式,及间距
  66. *
  67. * @param style titleLabel和imageView的布局样式
  68. * @param space titleLabel和imageView的间距
  69. */
  70. - (void)layoutButtonWithEdgeInsetsStyle:(RQButtonEdgeInsetsStyle)style
  71. imageTitleSpace:(CGFloat)space;
  72. @end
  73. NS_ASSUME_NONNULL_END