123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- //
- // KXKeyWordView.m
- // CAISHEN
- //
- // Created by kuxuan on 2017/12/5.
- // Copyright © 2017年 kuxuan. All rights reserved.
- //
- #import "KXKeyWordView.h"
- #import "KXKeyWordTool.h"
- @implementation KXKeyWordView
- - (instancetype)init
- {
- if (self = [super init]) {
- self.backgroundColor = [UIColor whiteColor];
- [self setupUI];
- }
- return self;
- }
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- self.backgroundColor = [UIColor whiteColor];
- [self setupUI];
- }
- return self;
- }
- - (void)setupUI
- {
- UILabel *keyWord = [[UILabel alloc]initWithFrame:CGRectMake(14, 0, 200, 42)];
- keyWord.text = @"热门关键词:";
- keyWord.textColor = [UIColor KXColorWithHex:0x9a9a9a];
- keyWord.font = FONT_SYS(14);
- [self addSubview:keyWord];
- }
- - (void)setItemArray:(NSArray *)itemArray
- {
- _itemArray = itemArray;
- for (int i=0; i<itemArray.count; i++) {
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- button.frame = CGRectMake((SCREEN_WIDTH/2)*(i%2), 42+42*(i/2), SCREEN_WIDTH/2, 42);
- button.contentEdgeInsets = UIEdgeInsetsMake(0, 14, 0, 0);
- button.titleLabel.font = FONT_SYS(14);
- [button setTitle:itemArray[i] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
- [button setTitleColor:[UIColor titleColor] forState:UIControlStateNormal];
- [self addSubview:button];
- }
-
- for (int i = 0; i < (itemArray.count + 1)/2; i++) {
- UILabel *hLabel = [[UILabel alloc]initWithFrame:CGRectMake(14, 42*(i+1), SCREEN_WIDTH - 28, 0.3)];
- hLabel.backgroundColor = [UIColor lineColor];
- [self addSubview:hLabel];
- }
-
- UILabel *vlabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2, 42, 0.3, 42*(itemArray.count + 1)/2)];
- vlabel.backgroundColor = [UIColor lineColor];
- [self addSubview:vlabel];
-
- self.frame = CGRectMake(0, 0, SCREEN_WIDTH, (itemArray.count + 1)/2*42+42);
- }
- - (void)buttonAction:(UIButton *)btn
- {
- self.keywordBlock(btn.titleLabel.text);
- }
- @end
|