UIButton+RQExtension.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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, readwrite, assign) NSString *rq_titleStr;
  20. @property (nonatomic)IBInspectable float fixWidthScreenFont;
  21. /**
  22. 添加 addtarget
  23. */
  24. - (void)addActionHandler:(TouchedBlock)touchHandler;
  25. /**
  26. * @brief 使用颜色设置按钮背景
  27. *
  28. * @param backgroundColor 背景颜色
  29. * @param state 按钮状态
  30. */
  31. - (void)setBackgroundColor:(UIColor *)backgroundColor forState:(UIControlState)state;
  32. /*
  33. * @brief
  34. *
  35. * @param frame frame
  36. * @param buttonTitle 标题
  37. * @param normalBGColor 未选中的背景色
  38. * @param selectBGColor 选中的背景色
  39. * @param normalColor 未选中的文字色
  40. * @param selectColor 选中的文字色
  41. * @param buttonFont 文字字体
  42. * @param cornerRadius 圆角值 没有则为0
  43. * @param doneBlock 点击事件
  44. *
  45. * @return
  46. */
  47. - (instancetype)initWithFrame:(CGRect)frame buttonTitle:(NSString *)buttonTitle normalBGColor:(UIColor *)normalBGColor selectBGColor:(nullable UIColor *)selectBGColor
  48. normalColor:(UIColor *)normalColor selectColor:(nullable UIColor *)selectColor buttonFont:(UIFont *)buttonFont cornerRadius:(CGFloat )cornerRadius
  49. doneBlock:(void(^)(UIButton *))doneBlock;
  50. + (UIButton *)initWithFrame:(CGRect)frame buttonTitle:(NSString *)buttonTitle normalBGColor:(UIColor *)normalBGColor selectBGColor:(UIColor *)selectBGColor
  51. normalColor:(UIColor *)normalColor selectColor:(UIColor *)selectColor buttonFont:(UIFont *)buttonFont cornerRadius:(CGFloat )cornerRadius
  52. doneBlock:(void(^)(UIButton *))doneBlock;
  53. /**默认的字体大小
  54. */
  55. - (void)setImage:(UIImage *)image withTitle:(NSString *)title forState:(UIControlState)stateType;
  56. - (void)setImage:(UIImage *)image withTitle:(NSString *)title Font:(CGFloat)font forState:(UIControlState)stateType;
  57. - (void)setTitle:(NSString*)title textColor:(UIColor*)color Font:(CGFloat)font fotState:(UIControlState)stateType;
  58. - (void)setImage:(UIImage *)image withTitle:(NSString*)title textColor:(UIColor*)color Font:(CGFloat)font fotState:(UIControlState)stateType;
  59. /**简化按钮事件添加。要求一定要实现btnClick;
  60. */
  61. -(void)target:(id)obj;
  62. -(void)target:(id)obj tag:(NSInteger)tag;
  63. -(void)setTitleNormal:(NSString*)title;
  64. -(void)setTitleSelect:(NSString*)title;
  65. /**
  66. * 设置button的titleLabel和imageView的布局样式,及间距
  67. *
  68. * @param style titleLabel和imageView的布局样式
  69. * @param space titleLabel和imageView的间距
  70. */
  71. - (void)layoutButtonWithEdgeInsetsStyle:(RQButtonEdgeInsetsStyle)style
  72. imageTitleSpace:(CGFloat)space;
  73. @end
  74. NS_ASSUME_NONNULL_END