123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- //
- // FKButtonChoiceMenu.m
- // FirstLink
- //
- // Created by ascii on 16/6/12.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKButtonChoiceMenu.h"
- //@interface FKButtonChoiceMenu ()
- //
- //@property ()
- //
- //@end
- @implementation FKButtonChoiceMenu
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- - (instancetype)initWithSectionTitles:(NSArray *)sectionTitles cancelTitle:(NSString *)cancelTitle {
- self = [super init];
- if (self) {
- UIButton *cancelButton = [self makeButtonWitTitle:cancelTitle tag:0];
- [self addSubview:cancelButton];
- [cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.bottom.right.equalTo(self);
- make.height.mas_equalTo(50);
- }];
-
- UIView *banner = [UIView new];
- banner.backgroundColor = [UIColor colorWithWhite:1 alpha:0.85];
- [self addSubview:banner];
- [banner mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self);
- make.bottom.equalTo(cancelButton.mas_top);
- make.height.mas_equalTo(10);
- }];
-
- NSInteger tag = 1;
- UIButton *choiceButton;
- UIView *preView = banner, *line;
- for (NSString *title in [sectionTitles reverseObjectEnumerator]) {
- choiceButton = [self makeButtonWitTitle:title tag:tag++];
-
- [self addSubview:choiceButton];
- [choiceButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self);
- make.bottom.equalTo(preView.mas_top);
- make.height.mas_equalTo(50);
- }];
-
- if (title != sectionTitles.firstObject) {
- line = [UIView new];
- line.backgroundColor = UIColorFromRGB(0xe5e5e5);
- [self addSubview:line];
- [line mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self);
- make.bottom.equalTo(choiceButton.mas_top);
- make.height.mas_equalTo(1.0/[UIScreen mainScreen].scale);
- }];
- }
-
- preView = line;
- }
- }
- return self;
- }
- #pragma mark - Action
- - (IBAction)clickButtonAction:(UIButton *)sender {
- if (self.clickCallback) {
- self.clickCallback(sender.tag);
- }
- }
- #pragma mark - Layout
- - (UIButton *)makeButtonWitTitle:(NSString *)title tag:(NSInteger)tag {
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- button.tag = tag;
- button.backgroundColor = [UIColor whiteColor];
- [button setTitle:title forState:UIControlStateNormal];
- [button.titleLabel setFont:[UIFont systemFontOfSize:16]];
- [button setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
-
- [button addTarget:self action:@selector(clickButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- return button;
- }
- @end
|