专栏名称: Cocoa开发者社区
CocoaChina苹果开发中文社区官方微信,提供教程资源、app推广营销、招聘、外包及培训信息、各类沙龙交流活动以及更多开发者服务。
目录
相关文章推荐
51好读  ›  专栏  ›  Cocoa开发者社区

UITableView实现格瓦拉飞天投票模块

Cocoa开发者社区  · 公众号  · ios  · 2016-08-24 08:49

正文

请到「今天看啥」查看全文


{

//根据数据算出每行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]







请到「今天看啥」查看全文


推荐文章
娱小读同学  ·  女生竟有A.G.U.Y 四个高潮点
8 年前
冯站长之家  ·  2017年5月29日历史上的今天(语音版)
8 年前
中原文化研究  ·  讲堂丨小标点,大学问
7 年前