Açıklama Yok

FKButtonChoiceMenu.m 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // FKButtonChoiceMenu.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/6/12.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKButtonChoiceMenu.h"
  9. //@interface FKButtonChoiceMenu ()
  10. //
  11. //@property ()
  12. //
  13. //@end
  14. @implementation FKButtonChoiceMenu
  15. /*
  16. // Only override drawRect: if you perform custom drawing.
  17. // An empty implementation adversely affects performance during animation.
  18. - (void)drawRect:(CGRect)rect {
  19. // Drawing code
  20. }
  21. */
  22. - (instancetype)initWithSectionTitles:(NSArray *)sectionTitles cancelTitle:(NSString *)cancelTitle {
  23. self = [super init];
  24. if (self) {
  25. UIButton *cancelButton = [self makeButtonWitTitle:cancelTitle tag:0];
  26. [self addSubview:cancelButton];
  27. [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.left.bottom.right.equalTo(self);
  29. make.height.mas_equalTo(50);
  30. }];
  31. UIView *banner = [UIView new];
  32. banner.backgroundColor = [UIColor colorWithWhite:1 alpha:0.85];
  33. [self addSubview:banner];
  34. [banner mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.right.equalTo(self);
  36. make.bottom.equalTo(cancelButton.mas_top);
  37. make.height.mas_equalTo(10);
  38. }];
  39. NSInteger tag = 1;
  40. UIButton *choiceButton;
  41. UIView *preView = banner, *line;
  42. for (NSString *title in [sectionTitles reverseObjectEnumerator]) {
  43. choiceButton = [self makeButtonWitTitle:title tag:tag++];
  44. [self addSubview:choiceButton];
  45. [choiceButton mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.right.equalTo(self);
  47. make.bottom.equalTo(preView.mas_top);
  48. make.height.mas_equalTo(50);
  49. }];
  50. if (title != sectionTitles.firstObject) {
  51. line = [UIView new];
  52. line.backgroundColor = UIColorFromRGB(0xe5e5e5);
  53. [self addSubview:line];
  54. [line mas_makeConstraints:^(MASConstraintMaker *make) {
  55. make.left.right.equalTo(self);
  56. make.bottom.equalTo(choiceButton.mas_top);
  57. make.height.mas_equalTo(1.0/[UIScreen mainScreen].scale);
  58. }];
  59. }
  60. preView = line;
  61. }
  62. }
  63. return self;
  64. }
  65. #pragma mark - Action
  66. - (IBAction)clickButtonAction:(UIButton *)sender {
  67. if (self.clickCallback) {
  68. self.clickCallback(sender.tag);
  69. }
  70. }
  71. #pragma mark - Layout
  72. - (UIButton *)makeButtonWitTitle:(NSString *)title tag:(NSInteger)tag {
  73. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  74. button.tag = tag;
  75. button.backgroundColor = [UIColor whiteColor];
  76. [button setTitle:title forState:UIControlStateNormal];
  77. [button.titleLabel setFont:[UIFont systemFontOfSize:16]];
  78. [button setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
  79. [button addTarget:self action:@selector(clickButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  80. return button;
  81. }
  82. @end