// // KBTitleMoreMeunView.m // YouHuiProject // // Created by 小花 on 2018/11/7. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBTitleMoreMeunView.h" @interface KBTitleMoreMeunView (){ NSArray *_buttons; NSString *_title; } @end @implementation KBTitleMoreMeunView - (instancetype)initWithFrame:(CGRect)frame buttonInfoArray:(NSArray *)array title:(NSString *)title{ self = [super initWithFrame:frame]; if (self) { _title = title; _buttons = array; self.backgroundColor = [UIColor whiteColor]; self.layer.cornerRadius = 6; self.layer.masksToBounds = YES; [self initSubViews]; } return self; } - (void)initSubViews { // NSArray *titles = @[@"我的粉丝",@"我的收藏",@"绑定邀请码",@"邀请好友",@"新手指南",@"用户反馈",@"五星好评",@"设置"]; UILabel *titleLb = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 200, Fitsize(36))]; titleLb.font = [UIFont systemFontOfSize:Fitsize(14)]; titleLb.textColor = [UIColor YHColorWithHex:0x000000]; titleLb.text = _title; [self addSubview:titleLb]; UILabel *Line = [[UILabel alloc] initWithFrame:CGRectMake(5, titleLb.bottom, self.width-10, 1)]; Line.backgroundColor = [UIColor yhGrayColor]; [self addSubview:Line]; CGFloat width = self.width/4; CGFloat height = width; for (int i = 0; i < _buttons.count; i++) { UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(width * (i%4),Line.bottom+ (i/4)*height, width, height)]; NSDictionary *dict = _buttons[i]; [button setTitle:dict[@"title"] forState:UIControlStateNormal]; [button setImage:[UIImage imageNamed:dict[@"image"]] forState:UIControlStateNormal]; [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; [button setTitleColor:[UIColor YHColorWithHex:0x7c7c7c] forState:UIControlStateNormal]; button.titleLabel.font = [UIFont systemFontOfSize:12]; button.tag = 10000 + i; [button setButtonImageTitleStyle:ButtonImageTitleStyleTop padding:15]; [self addSubview:button]; } NSInteger row = _buttons.count/4; if (_buttons.count%4 != 0) { row += 1; } self.height = Line.bottom + row * height; } - (void)buttonAction:(UIButton *)sender { if (self.delelgate && [self.delelgate respondsToSelector:@selector(titleMorenMenu:Button:clickIndex:)]) { [self.delelgate titleMorenMenu:self Button:sender clickIndex:sender.tag-10000]; } } @end