MHRadioButton.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // MHRadioButton.h
  3. //
  4. //
  5. // Created by Macro on 14-11-9.
  6. // Copyright (c) 2014年 Macro. All rights reserved.
  7. //
  8. #import <UIKit/UIKit.h>
  9. // 按钮点击宽度 可根据实际更改
  10. static const NSUInteger kRadioButtonWidth = 22;
  11. // 按钮点击高度 可根据实际更改
  12. static const NSUInteger kRadioButtonHeight = 22;
  13. /*!
  14. * @author Macro, 14-11-09
  15. *
  16. * @brief 协议, RadioButton的选中项改变时, 触发此方法
  17. */
  18. @protocol MHRadioButtonDelegate <NSObject>
  19. /*!
  20. * @author Macro, 14-11-09
  21. *
  22. * @brief 选项改变
  23. *
  24. * @param index NSUInteger: 按钮下标
  25. * @param groupID NSString *:单个按钮所在的"组号"
  26. */
  27. - (void)radioButtonSelectedAtIndex:(NSUInteger)index inGroup:(NSString *)groupID;
  28. @end
  29. @interface MHRadioButton : UIView
  30. /*!
  31. * @author Macro, 14-11-09
  32. *
  33. * @brief 初始化一个RadioButton
  34. *
  35. * @param groupId NSString *:按钮的组号
  36. * @param index NSUInteger:按钮在组中的下标, 建议从0开始编号
  37. *
  38. * @return RadioButton
  39. */
  40. - (instancetype)initWithGroupId:(NSString *)groupId
  41. atIndex:(NSUInteger)index;
  42. /*!
  43. * @author Macro, 14-11-10
  44. *
  45. * @brief 设置RadioButton为选中状态
  46. */
  47. - (void)selected;
  48. /*!
  49. * @author Macro, 14-11-10
  50. *
  51. * @brief 添加观察者
  52. *
  53. * @param observer 观察者
  54. * @param groupId 组号
  55. */
  56. + (void)addObserver:(id <MHRadioButtonDelegate>)observer
  57. forFroupId:(NSString *)groupId;
  58. /*!
  59. * @author Macro, 14-11-10
  60. *
  61. * @brief 获取特定组号的那组RadioButton的选中下标
  62. *
  63. * @param groupId 组号
  64. *
  65. * @return 下标 -1表示组号不存在
  66. */
  67. + (NSUInteger)getIndexWithGroupId:(NSString *)groupId;
  68. @end