CustomRadioGroup.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // CustomRadioGroup.h
  3. // JasonDevelop
  4. //
  5. // Created by Jason Lee on 3/10/14.
  6. // Copyright (c) jasondevelop. All rights reserved.
  7. //
  8. @import UIKit;
  9. @protocol CustomRadioGroupDelegate;
  10. @protocol CustomRadioReusableGroupDelegate;
  11. @protocol CustomRadioButtonDelegate <NSObject>
  12. @optional
  13. - (void)didCheckRadioButton:(id)sender;
  14. @end
  15. @interface CustomRadioButton : UIButton {
  16. @protected
  17. UIImage *_normalImage, *_highlightImage;
  18. UIImage *_bgNormalImage, *_bgHighlightImage;
  19. UIColor *_titleColorNormal, *_titleColorHighlight;
  20. UIEdgeInsets _insets;
  21. UIEdgeInsets _bgInsets;
  22. BOOL _checked;
  23. }
  24. @property (weak, nonatomic) id <CustomRadioButtonDelegate> delegate;
  25. @property (strong, nonatomic) id value;
  26. @property (assign, nonatomic) BOOL checked;
  27. @property (assign, nonatomic) IBInspectable CGRect imageRect; //set with interfacebuilder
  28. @property (strong, nonatomic) UIImage *normalImage;
  29. @property (strong, nonatomic) UIImage *highlightImage;
  30. @property (strong, nonatomic) IBInspectable UIImage *bgImageNormal;
  31. @property (strong, nonatomic) IBInspectable UIImage *bgImageHighlight;
  32. @property (strong, nonatomic) IBInspectable UIColor *titleColorNormal;
  33. @property (strong, nonatomic) IBInspectable UIColor *titleColorHighlight;
  34. - (instancetype)initWithFrame:(CGRect)frame normalImage:(UIImage *)normalImage highlightImage:(UIImage *)highlightImage;
  35. - (BOOL)getRadioStatusFromValue;
  36. @end
  37. @interface CustomBgRadioButton : CustomRadioButton
  38. @property (assign, nonatomic) BOOL checked;
  39. @property (assign, nonatomic) IBInspectable CGRect rectForCapBg; //set with interfacebuilder
  40. - (instancetype)initWithFrame:(CGRect)frame bgNormalImage:(UIImage *)bgNormalImage bgHighlightImage:(UIImage *)bgHighlightImage rectForCapBg:(CGRect)rectForCapBg;
  41. @end
  42. //CAUTION: don't use in reusable tableview.
  43. @interface CustomRadioGroup : NSObject
  44. @property (weak, nonatomic) id <CustomRadioGroupDelegate> delegate;
  45. @property (readonly, nonatomic) NSInteger count;
  46. @property (readonly, nonatomic) NSArray *rdoBtns;
  47. - (id)initWithRadioButtons:(id)buttons, ... NS_REQUIRES_NIL_TERMINATION;
  48. - (void)addRadioButton:(CustomRadioButton *)button;
  49. - (void)reset;
  50. - (id)valueForChecked;
  51. - (id)titleForChecked;
  52. - (void)someRadioButtonTouched:(id)sender;
  53. @end
  54. @protocol CustomRadioGroupDelegate <NSObject>
  55. @optional
  56. - (void)didSomeRadioButtonTouched:(id)sender;
  57. @end
  58. //use in resuable tableview
  59. @interface CustomRadioReusableGroup : NSObject
  60. @property (weak, nonatomic) id <CustomRadioReusableGroupDelegate> delegate;
  61. @property (weak, nonatomic) UITableView *tableView;
  62. @property (assign, nonatomic) NSInteger section;
  63. @property (readonly, nonatomic) id valueForChecked;
  64. @property (readonly, nonatomic) NSMutableArray *values;
  65. - (void)reset;
  66. - (void)addRadioButton:(CustomRadioButton *)rbtn;
  67. - (void)someRadioButtonTouched:(CustomRadioButton *)touchedRbtn;
  68. @end
  69. @protocol CustomRadioReusableGroupDelegate <NSObject>
  70. @optional
  71. - (void)didSomeReuableRadioButtonTouched:(id)sender;
  72. @end