正文
{
//根据数据算出每行cell的实际高度
_title = title;
CGFloat title_H = [title boundingRectWithSize:CGSizeMake(ZFVoteTableViewMax_W - percentLable_W - thumbUpView_WH - 85, 100)
options:NSStringDrawingUsesFontLeading|NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15.0]}
context:nil].size.height;
self.voteCell_H = title_H + 30;
}
设置cell的内边距离及x值,利用setFrame:方法改变原来父类算好的frame实现cell有内边距离,达到实现相邻两条cell不连接在一起的效果
-(void)setFrame:(CGRect)frame{
if (frame.size.width == ZFVoteTableViewMax_W) {//初始化就设置cell的内边距
frame = UIEdgeInsetsInsetRect(frame,
UIEdgeInsetsMake(ZFVoteCellTopBottomInset,
ZFVoteCellLeftRightInset,
ZFVoteCellTopBottomInset,
ZFVoteCellLeftRightInset));
}else{//重复利用的时候改变它的x值
frame.origin.x += ZFVoteCellLeftRightInset;
}
[super setFrame:frame];
}
创建投票主控件并添加到cell上,投票主控件就是所有要展示动画效果的控件集合,有cell了为什么还需要它,其实说白了它就是打酱油的,只是为了呈现动画的一种载体,在看下面一条就了解了
-(void)initSubviews{
ZFPercentBar *bar = [[ZFPercentBar alloc]initWithFrame:self.bounds];
self.bar = bar;
[self addSubview:bar];
UIImageView *thumbUpView = [[UIImageView alloc]init];
self.thumbUpView = thumbUpView;
[self addSubview:thumbUpView];
UILabel *percentLable = [UILabel labelWithFont:[UIFont systemFontOfSize:13.0]
textColor:[UIColor lightGrayColor]
textAlignment:NSTextAlignmentRight
numberOfLines:1];
self.percentLable = percentLable;
[self addSubview:percentLable];
UILabel *voteLabel = [UILabel labelWithFont:[UIFont systemFontOfSize:15.0]