线上所有马甲包模板,与《猎豆》同UI。域名zhuadd

HSQTimeLineTableCell.m 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. //
  2. // HSQTimeLineTableCell.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/12/27.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "HSQTimeLineTableCell.h"
  9. #import "HSQTimeLineCommentView.h"
  10. #import "UIView+SDAutoLayout.h"
  11. #import "CCCopyLabel.h"
  12. @interface HSQTimeLineTableCell ()
  13. @property (nonatomic, strong) UIImageView *iconView;
  14. @property (nonatomic, strong) UILabel *name;
  15. @property (nonatomic, strong) CCCopyLabel *title;
  16. @property (nonatomic, strong) UIView *goodBg;
  17. @property (nonatomic, strong) UIImageView *goodIcon;
  18. @property (nonatomic, strong) UILabel *goodTitle;
  19. @property (nonatomic, strong) UILabel *disPrice;
  20. //@property (nonatomic, strong) UILabel *localLabel;
  21. @property (nonatomic, strong) UILabel *timeLabel;
  22. @property (nonatomic, strong) UIButton *shareButton;
  23. //@property (nonatomic, strong) HSQTimeLineCommentView *commentView;
  24. @property (nonatomic, strong) UIImageView *ticketNumber; //
  25. @property (nonatomic, strong) UILabel *zheKou; // 几折,或者几元券
  26. @property (nonatomic, strong) UILabel *ticketType;
  27. @property (nonatomic, strong) UIView *tapView;
  28. @end
  29. @implementation HSQTimeLineTableCell
  30. - (void)awakeFromNib {
  31. [super awakeFromNib];
  32. // Initialization code
  33. }
  34. + (instancetype)cellWithTableView:(UITableView *)tableView {
  35. static NSString *cellID = nil;
  36. cellID = NSStringFromClass([self class]);
  37. HSQTimeLineTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
  38. if (!cell) {
  39. cell = [[HSQTimeLineTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
  40. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  41. }
  42. return cell;
  43. }
  44. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  45. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  46. if (self) {
  47. [self initSubViews];
  48. }
  49. return self;
  50. }
  51. - (void)initSubViews {
  52. [self.contentView addSubview:self.iconView];
  53. [self.contentView addSubview:self.name];
  54. [self.contentView addSubview:self.title];
  55. [self.contentView addSubview:self.goodBg];
  56. [self.goodBg addSubview:self.goodIcon];
  57. [self.goodBg addSubview:self.goodTitle];
  58. [self.goodBg addSubview:self.disPrice];
  59. [self.goodBg addSubview:self.ticketNumber];
  60. [self.goodBg addSubview:self.tapView];
  61. [self.ticketNumber addSubview:self.ticketType];
  62. [self.ticketNumber addSubview:self.zheKou];
  63. // [self.contentView addSubview:self.localLabel];
  64. [self.contentView addSubview:self.timeLabel];
  65. [self.contentView addSubview:self.shareButton];
  66. // [self.contentView addSubview:self.commentView];
  67. [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.left.mas_equalTo(10);
  69. make.top.mas_equalTo(14);
  70. make.width.height.mas_equalTo(42);
  71. }];
  72. [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.left.mas_equalTo(self.iconView.mas_right).mas_offset(10);
  74. make.top.mas_equalTo(17);
  75. make.right.mas_equalTo(-10);
  76. }];
  77. [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.top.mas_equalTo(self.name.mas_bottom).mas_offset(7);
  79. make.left.mas_equalTo(self.name);
  80. make.right.mas_equalTo(-10);
  81. }];
  82. [self.goodBg mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.mas_equalTo(self.name);
  84. make.right.mas_equalTo(-10);
  85. make.top.mas_equalTo(self.title.mas_bottom).mas_offset(7);
  86. make.height.mas_equalTo(90);
  87. }];
  88. [self.tapView mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
  90. }];
  91. // [self.localLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  92. // make.left.mas_equalTo(self.goodBg);
  93. // make.right.mas_equalTo(-10);
  94. // make.top.mas_equalTo(self.goodBg.mas_bottom).mas_offset(8);
  95. // }];
  96. [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.left.mas_equalTo(self.goodBg);
  98. make.top.mas_equalTo(self.goodBg.mas_bottom).mas_offset(8);
  99. make.right.mas_equalTo(-10);
  100. }];
  101. [self.shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.right.mas_equalTo(-10);
  103. make.centerY.mas_equalTo(self.timeLabel.mas_centerY);
  104. make.width.mas_equalTo(50);
  105. make.height.mas_equalTo(20);
  106. }];
  107. [self.goodIcon mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.left.top.mas_equalTo(5);
  109. make.width.height.mas_equalTo(80);
  110. }];
  111. [self.goodTitle mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.left.mas_equalTo(self.goodIcon.mas_right).mas_offset(7);
  113. make.right.mas_equalTo(-7);
  114. make.top.mas_equalTo(self.goodIcon.mas_top).mas_offset(4);
  115. }];
  116. [self.disPrice mas_makeConstraints:^(MASConstraintMaker *make) {
  117. make.left.mas_equalTo(self.goodTitle);
  118. make.centerY.mas_equalTo(self.goodIcon.mas_centerY);
  119. }];
  120. [self.ticketNumber mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.left.mas_equalTo(self.goodTitle.mas_left);
  122. make.width.mas_equalTo(64);
  123. make.height.mas_equalTo(14);
  124. make.bottom.mas_equalTo(-10);
  125. }];
  126. [self.ticketType mas_makeConstraints:^(MASConstraintMaker *make) {
  127. make.left.top.bottom.mas_equalTo(0);
  128. make.width.mas_equalTo(20);
  129. }];
  130. [self.zheKou mas_makeConstraints:^(MASConstraintMaker *make) {
  131. make.left.mas_equalTo(self.ticketType.mas_right);
  132. make.top.mas_equalTo(0);
  133. make.height.mas_equalTo(14);
  134. make.width.mas_equalTo(44);
  135. }];
  136. // _commentView.sd_layout
  137. // .leftEqualToView(self.name)
  138. // .rightSpaceToView(self.contentView, 10)
  139. // .topSpaceToView(_timeLabel, 10);
  140. }
  141. - (void)shareClick {
  142. if (self.shareClickBlock) {
  143. self.shareClickBlock();
  144. }
  145. }
  146. -(void)setLineSpace:(CGFloat)lineSpace withText:(NSString *)text inLabel:(UILabel *)label{
  147. if (!text || !label) {
  148. return;
  149. }
  150. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  151. paragraphStyle.lineSpacing = lineSpace; //设置行间距
  152. paragraphStyle.lineBreakMode = label.lineBreakMode;
  153. // paragraphStyle.alignment = label.textAlignment;
  154. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];
  155. [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
  156. label.attributedText = attributedString;
  157. }
  158. - (void)setModel:(HSQTimeLineModel *)model {
  159. _model = model;
  160. [self.iconView sd_setFadeImageWithURL:[NSURL URLWithString:model.subscribe_img] placeholderImage:nil options:0 progress:nil completed:nil];
  161. self.name.text = model.subscribe_title;
  162. // self.title.text = model.show_content;
  163. [self setLineSpace:4 withText:model.show_content inLabel:self.title];
  164. [self.goodIcon sd_setFadeImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil options:0 progress:nil completed:nil];;
  165. self.goodTitle.text = model.title;
  166. self.disPrice.text = [NSString stringWithFormat:@"¥%@",model.discount_price];
  167. self.timeLabel.text = model.pass_time;
  168. // self.localLabel.text = model.location;
  169. //折后价
  170. NSString *disStr;
  171. if ([model.is_coupon boolValue]) {
  172. disStr = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
  173. self.zheKou.text = [NSString stringWithFormat:@"%@元",model.coupon_price];
  174. self.ticketType.text = @"券";
  175. }else {
  176. disStr = [NSString stringWithFormat:@"¥%.2f",[model.discount_price floatValue]];
  177. self.zheKou.text = [NSString stringWithFormat:@"%@折",model.coupon_price];
  178. self.ticketType.text = @"折";
  179. }
  180. //券相关
  181. self.ticketNumber.hidden = ![model.is_coupon boolValue];
  182. UIView *bottomView;
  183. bottomView = _timeLabel;
  184. // [self.commentView setupWithLikeItemsArray:model.shareUser contentText:model.show_comment];
  185. // if (!model.shareUser.count && model.show_comment.length==0) {
  186. // bottomView = _timeLabel;
  187. // } else {
  188. // bottomView = _commentView;
  189. // }
  190. [self setupAutoHeightWithBottomView:bottomView bottomMargin:15];
  191. }
  192. - (void)tapAction {
  193. if (self.tapBlock) {
  194. self.tapBlock();
  195. }
  196. }
  197. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  198. [super setSelected:selected animated:animated];
  199. // Configure the view for the selected state
  200. }
  201. - (UIImageView *)iconView {
  202. if (!_iconView) {
  203. _iconView = [[UIImageView alloc] init];
  204. _iconView.layer.cornerRadius = 21;
  205. _iconView.layer.masksToBounds = YES;
  206. _iconView.backgroundColor = [UIColor yhGrayColor];
  207. }
  208. return _iconView;
  209. }
  210. - (UILabel *)name {
  211. if (!_name) {
  212. _name = [[UILabel alloc] init];
  213. _name.font = [UIFont boldSystemFontOfSize:17];
  214. _name.textColor = [UIColor YHColorWithHex:0x576B95];
  215. }
  216. return _name;
  217. }
  218. - (CCCopyLabel *)title {
  219. if (!_title) {
  220. _title = [[CCCopyLabel alloc] init];
  221. _title.font = [UIFont fontWithName:@"HelveticaNeue" size:17];
  222. _title.textColor = [UIColor YHColorWithHex:0x222222];
  223. _title.numberOfLines = 0;
  224. _title.longTapBlock = ^{
  225. [MobClick event:OptimizingCircleCopyTopContent];
  226. };
  227. }
  228. return _title;
  229. }
  230. - (UIView *)goodBg {
  231. if (!_goodBg) {
  232. _goodBg = [[UIView alloc] init];
  233. _goodBg.backgroundColor = [UIColor YHColorWithHex:0xF3F3F5 alpha:0.9];
  234. }
  235. return _goodBg;
  236. }
  237. //- (UILabel *)localLabel {
  238. // if (!_localLabel) {
  239. // _localLabel = [[UILabel alloc] init];
  240. // _localLabel.font = [UIFont systemFontOfSize:14];
  241. // _localLabel.textColor = [UIColor YHColorWithHex:0x576B95];
  242. // }
  243. // return _localLabel;
  244. //}
  245. - (UILabel *)timeLabel {
  246. if (!_timeLabel) {
  247. _timeLabel = [[UILabel alloc] init];
  248. _timeLabel.font = [UIFont systemFontOfSize:14];
  249. _timeLabel.textColor = [UIColor YHColorWithHex:0xB2B2B2];
  250. }
  251. return _timeLabel;
  252. }
  253. - (UIButton *)shareButton {
  254. if (!_shareButton) {
  255. _shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
  256. [_shareButton setTitle:@"分享" forState:UIControlStateNormal];
  257. _shareButton.layer.cornerRadius = 10;
  258. _shareButton.layer.borderColor = [UIColor YHColorWithHex:0x576B95].CGColor;
  259. _shareButton.layer.borderWidth = 1;
  260. [_shareButton setTitleColor:[UIColor YHColorWithHex:0x576B95] forState:UIControlStateNormal];
  261. _shareButton.titleLabel.font = [UIFont systemFontOfSize:11];
  262. [_shareButton addTarget:self action:@selector(shareClick) forControlEvents:UIControlEventTouchUpInside];
  263. }
  264. return _shareButton;
  265. }
  266. - (UIImageView *)goodIcon {
  267. if (!_goodIcon) {
  268. _goodIcon = [[UIImageView alloc] init];
  269. _goodIcon.backgroundColor = [UIColor whiteColor];
  270. }
  271. return _goodIcon;
  272. }
  273. - (UILabel *)goodTitle {
  274. if (!_goodTitle) {
  275. _goodTitle = [[UILabel alloc] init];
  276. _goodTitle.font = [UIFont systemFontOfSize:14];
  277. _goodTitle.textColor = [UIColor blackColor];
  278. }
  279. return _goodTitle;
  280. }
  281. - (UILabel *)disPrice {
  282. if (!_disPrice) {
  283. _disPrice = [[UILabel alloc] init];
  284. _disPrice.textColor = [UIColor homeRedColor];
  285. _disPrice.font = [UIFont systemFontOfSize:16];
  286. }
  287. return _disPrice;
  288. }
  289. //- (HSQTimeLineCommentView *)commentView {
  290. // if (!_commentView) {
  291. // _commentView = [HSQTimeLineCommentView new];
  292. // }
  293. // return _commentView;
  294. //}
  295. - (UIImageView *)ticketNumber {
  296. if (!_ticketNumber) {
  297. _ticketNumber = [[UIImageView alloc] init];
  298. _ticketNumber.image = [UIImage imageNamed:@"tickY"];
  299. }
  300. return _ticketNumber;
  301. }
  302. - (UILabel *)zheKou {
  303. if (!_zheKou) {
  304. _zheKou = [[UILabel alloc] init];
  305. _zheKou.textColor = [UIColor homeRedColor];
  306. _zheKou.textAlignment = NSTextAlignmentCenter;
  307. _zheKou.font = [UIFont systemFontOfSize:10];
  308. }
  309. return _zheKou;
  310. }
  311. - (UILabel *)ticketType {
  312. if (!_ticketType) {
  313. _ticketType = [[UILabel alloc] init];
  314. _ticketType.font = [UIFont systemFontOfSize:10];
  315. _ticketType.textAlignment = NSTextAlignmentCenter;
  316. _ticketType.textColor = [UIColor homeRedColor];
  317. }
  318. return _ticketType;
  319. }
  320. - (UIView *)tapView {
  321. if (!_tapView) {
  322. _tapView = [[UIView alloc] init];
  323. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
  324. [_tapView addGestureRecognizer:tap];
  325. }
  326. return _tapView;
  327. }
  328. @end