口袋优选

KBMoreMenuView.m 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. //
  2. // KBMoreMenuView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/5/17.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBMoreMenuView.h"
  9. @interface KBMoreMenuView (){
  10. NSArray *_buttons;
  11. }
  12. @end
  13. @implementation KBMoreMenuView
  14. - (instancetype)initWithFrame:(CGRect)frame buttonInfoArray:(NSArray *)array{
  15. self = [super initWithFrame:frame];
  16. if (self) {
  17. _buttons = array;
  18. self.backgroundColor = [UIColor whiteColor];
  19. self.layer.cornerRadius = 6;
  20. self.layer.masksToBounds = YES;
  21. [self initSubViews];
  22. }
  23. return self;
  24. }
  25. - (void)initSubViews {
  26. // NSArray *titles = @[@"我的粉丝",@"我的收藏",@"绑定邀请码",@"邀请好友",@"新手指南",@"用户反馈",@"五星好评",@"设置"];
  27. CGFloat width = self.width/4;
  28. CGFloat height = self.width/4;
  29. for (int i = 0; i < _buttons.count; i++) {
  30. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(width * (i%4), 0, width, height)];
  31. NSDictionary *dict = _buttons[i];
  32. [button setTitle:dict[@"title"] forState:UIControlStateNormal];
  33. [button setImage:[UIImage imageNamed:dict[@"image"]] forState:UIControlStateNormal];
  34. [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  35. [button setTitleColor:[UIColor YHColorWithHex:0x7c7c7c] forState:UIControlStateNormal];
  36. button.titleLabel.font = [UIFont systemFontOfSize:12];
  37. button.tag = 10000 + i;
  38. [button setButtonImageTitleStyle:ButtonImageTitleStyleTop padding:15];
  39. [self addSubview:button];
  40. }
  41. }
  42. - (void)buttonAction:(UIButton *)sender {
  43. if (self.delelgate && [self.delelgate respondsToSelector:@selector(morenMenu:Button:clickIndex:)]) {
  44. [self.delelgate morenMenu:self Button:sender clickIndex:sender.tag-10000];
  45. }
  46. }
  47. @end