Açıklama Yok

KXKeyWordView.m 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // KXKeyWordView.m
  3. // CAISHEN
  4. //
  5. // Created by kuxuan on 2017/12/5.
  6. // Copyright © 2017年 kuxuan. All rights reserved.
  7. //
  8. #import "KXKeyWordView.h"
  9. #import "KXKeyWordTool.h"
  10. @implementation KXKeyWordView
  11. - (instancetype)init
  12. {
  13. if (self = [super init]) {
  14. self.backgroundColor = [UIColor whiteColor];
  15. [self setupUI];
  16. }
  17. return self;
  18. }
  19. - (instancetype)initWithFrame:(CGRect)frame{
  20. if (self = [super initWithFrame:frame]) {
  21. self.backgroundColor = [UIColor whiteColor];
  22. [self setupUI];
  23. }
  24. return self;
  25. }
  26. - (void)setupUI
  27. {
  28. UILabel *keyWord = [[UILabel alloc]initWithFrame:CGRectMake(14, 0, 200, 42)];
  29. keyWord.text = @"热门关键词:";
  30. keyWord.textColor = [UIColor KXColorWithHex:0x9a9a9a];
  31. keyWord.font = FONT_SYS(14);
  32. [self addSubview:keyWord];
  33. }
  34. - (void)setItemArray:(NSArray *)itemArray
  35. {
  36. _itemArray = itemArray;
  37. for (int i=0; i<itemArray.count; i++) {
  38. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  39. button.frame = CGRectMake((SCREEN_WIDTH/2)*(i%2), 42+42*(i/2), SCREEN_WIDTH/2, 42);
  40. button.contentEdgeInsets = UIEdgeInsetsMake(0, 14, 0, 0);
  41. button.titleLabel.font = FONT_SYS(14);
  42. [button setTitle:itemArray[i] forState:UIControlStateNormal];
  43. [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  44. [button setTitleColor:[UIColor titleColor] forState:UIControlStateNormal];
  45. [self addSubview:button];
  46. }
  47. for (int i = 0; i < (itemArray.count + 1)/2; i++) {
  48. UILabel *hLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 42*(i+1), SCREEN_WIDTH - 28, 0.3)];
  49. hLabel.backgroundColor = [UIColor lineColor];
  50. [self addSubview:hLabel];
  51. }
  52. UILabel *vlabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2, 42, 0.3, 42*(itemArray.count + 1)/2)];
  53. vlabel.backgroundColor = [UIColor lineColor];
  54. [self addSubview:vlabel];
  55. self.frame = CGRectMake(0, 0, SCREEN_WIDTH, (itemArray.count + 1)/2*42+42);
  56. }
  57. - (void)buttonAction:(UIButton *)btn
  58. {
  59. self.keywordBlock(btn.titleLabel.text);
  60. }
  61. @end