热更新demo

CateView.m 2.9KB

    // // CateView.m // ThePaperBase // // Created by zhousan on 15/9/2. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "CateView.h" #define ITEM_WIDTH (rect_screen.size.width - 40)/3 #define ITEM_HEIGHT 70*rect_screen.size.width/320 @interface CateView () @end @implementation CateView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } return self; } - (void)setCateListArray:(NSMutableArray *)cateListArray { if (_cateListArray != cateListArray) { _cateListArray = cateListArray; for (int i=0; i<cateListArray.count; i++) { categoryBO *cate = _cateListArray[i]; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.tag = i+100; button.frame = CGRectMake((i%3)*ITEM_WIDTH, (i/3)*ITEM_HEIGHT, ITEM_WIDTH, ITEM_HEIGHT); [button addTarget:self action:@selector(itemClick:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:button]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, ITEM_WIDTH, 21)]; label.textAlignment = NSTextAlignmentCenter; label.font = appFont(TEXT_ONE_LEVELSIZE, NO); label.textColor = [UIColor colorWithHexString:TextBlack]; label.text = cate.name; [button addSubview:label]; UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(label.frame)+4, ITEM_WIDTH, 10)]; label1.textAlignment = NSTextAlignmentCenter; label1.font = appFont(TEXT_SEVEN_LEVELSIZE, NO); label1.textColor = [UIColor colorWithHexString:TextBlack]; label1.text = cate.enname; [button addSubview:label1]; if (i%3 == 1) { UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(ITEM_WIDTH, 25+ITEM_HEIGHT*(i/3), 0.5, 18)]; lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; [self addSubview:lineView]; } else if (i%3 == 2) { UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(2*ITEM_WIDTH, 25+ITEM_HEIGHT*(i/3), 0.5, 18)]; lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; [self addSubview:lineView]; } } } } - (void)itemClick:(UIButton *)sender { if ([self.delegate respondsToSelector:@selector(cateButtonClickWith:)]) { categoryBO *cate = self.cateListArray[sender.tag-100]; [self.delegate cateButtonClickWith:cate]; } } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end