BGDynamicCell.m 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. //
  2. // BGDynamicCell.m
  3. // BuguLive
  4. //
  5. // Created by fanwe2014 on 2017/3/15.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "BGDynamicCell.h"
  9. #define kPicDiv 5.0f
  10. @implementation BGDynamicCell
  11. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  12. {
  13. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
  14. {
  15. self.contentView.bounds = [UIScreen mainScreen].bounds;
  16. self.selectionStyle = UITableViewCellSelectionStyleNone;
  17. }
  18. return self ;
  19. }
  20. -(void)setData:(PersonCenterListModel *)data andRow:(int)row
  21. {
  22. _data = data;
  23. _row = row;
  24. for(UIView *view in [self.contentView subviews])
  25. {
  26. [view removeFromSuperview];
  27. }
  28. [self setHeadView];
  29. [self setBodyView];
  30. [self setZanReplyBar];
  31. }
  32. #pragma mark 头部
  33. -(void)setHeadView
  34. {
  35. //头像
  36. _headView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 42, 42)];
  37. _headView.userInteractionEnabled = YES;
  38. [self.contentView addSubview:_headView];
  39. _headView.layer.cornerRadius = 21;
  40. _headView.layer.masksToBounds = YES;
  41. _headView.tag = 100*_row+21;
  42. [_headView sd_setImageWithURL:[NSURL URLWithString:_data.head_image] placeholderImage:kDefaultPreloadHeadImg];
  43. UITapGestureRecognizer *headTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headTap:)];
  44. [self.headView addGestureRecognizer:headTap];
  45. //认证
  46. self.iconView = [[UIImageView alloc]initWithFrame:CGRectMake(42, 42, 9, 9)];
  47. [self.contentView addSubview:self.iconView];
  48. if ([_data.is_authentication intValue] == 2)
  49. {
  50. self.iconView.hidden = NO;
  51. self.iconView.image = [UIImage imageNamed:@"fw_SCell_vip"];
  52. }else
  53. {
  54. self.iconView.hidden = YES;
  55. }
  56. //名字
  57. self.nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(62, 10, kScreenW-42-80-70, 20)];
  58. self.nameLabel.font = [UIFont systemFontOfSize:14];
  59. self.nameLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  60. self.nameLabel.numberOfLines = 1;
  61. self.nameLabel.textColor = kAppGrayColor1;
  62. self.nameLabel.textAlignment = NSTextAlignmentLeft;
  63. [self.contentView addSubview:self.nameLabel];
  64. self.nameLabel.attributedText = [[NSAttributedString alloc]initWithString:_data.nick_name];
  65. //顶置
  66. self.topView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenW-42-80, 13, 42, 14)];
  67. self.topView.image = [UIImage imageNamed:@"fw_personCenter_hadTop"];
  68. [self.contentView addSubview:self.topView];
  69. if ([_data.is_top intValue] == 1)
  70. {
  71. if ([_data.is_show_top intValue] == 1)
  72. {
  73. self.topView.userInteractionEnabled = YES;
  74. self.topView.hidden = NO;
  75. }else
  76. {
  77. self.topView.userInteractionEnabled = NO;
  78. self.topView.hidden = YES;
  79. }
  80. }else
  81. {
  82. self.topView.userInteractionEnabled = NO;
  83. self.topView.hidden = YES;
  84. }
  85. self.topView.tag =100*_row+20;
  86. UITapGestureRecognizer*tapGesture6 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onPressImage:)];
  87. [self.topView addGestureRecognizer:tapGesture6];
  88. //时间
  89. self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenW-80, 10, 70, 20)];
  90. self.timeLabel.font = [UIFont systemFontOfSize:11];
  91. self.timeLabel.textColor = RGB(153, 153, 153);
  92. self.timeLabel.textAlignment = NSTextAlignmentRight;
  93. [self.contentView addSubview:self.timeLabel];
  94. self.timeLabel.text = _data.left_time;
  95. }
  96. #pragma mark 中间部分
  97. - (void)setBodyView
  98. {
  99. //内容
  100. CGFloat bodyViewWidth = kScreenW - 60 - 32;
  101. CGFloat bodyViewAddHight = 0;
  102. NSString *content = _data.content;
  103. TTTAttributedLabel * contentLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(0, 0, bodyViewWidth, 0)];
  104. contentLabel.textColor = RGB(153, 153, 153);
  105. contentLabel.numberOfLines = 0;
  106. //contentLabel.enabledTextCheckingTypes = NSTextCheckingTypeLink;
  107. contentLabel.delegate = self;
  108. if (content != nil && content.length > 0)
  109. {
  110. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
  111. paragraphStyle.maximumLineHeight = 18.0f;
  112. paragraphStyle.minimumLineHeight = 16.0f;
  113. paragraphStyle.firstLineHeadIndent = 0.0f;
  114. paragraphStyle.lineSpacing = 6.0f;
  115. paragraphStyle.firstLineHeadIndent = 0.0f;
  116. paragraphStyle.headIndent = 0.0f;
  117. paragraphStyle.alignment = NSTextAlignmentLeft;
  118. UIFont *font = [UIFont systemFontOfSize:14];
  119. NSDictionary *attributes = @{ NSFontAttributeName:font, NSParagraphStyleAttributeName:paragraphStyle,NSForegroundColorAttributeName:RGB(153, 153, 153)};
  120. contentLabel.attributedText = [[NSAttributedString alloc]initWithString:content attributes:attributes];
  121. contentLabel.textColor = RGB(153, 153, 153);
  122. CGSize size = CGSizeMake(bodyViewWidth, 1000.0f);
  123. CGSize finalSize = [contentLabel sizeThatFits:size];
  124. contentLabel.frame = CGRectMake(0, 0, finalSize.width, finalSize.height);
  125. //利用富文本实现URL的点击事件http://blog.csdn.net/liyunxiangrxm/article/details/53410919
  126. contentLabel.lineBreakMode = NSLineBreakByWordWrapping;
  127. contentLabel.linkAttributes = @{(NSString *)kCTUnderlineStyleAttributeName : [NSNumber numberWithBool:YES],
  128. (NSString*)kCTForegroundColorAttributeName : (id)[[UIColor blueColor] CGColor]};
  129. //contentLabel.highlightedTextColor = [UIColor whiteColor];
  130. contentLabel.highlightedTextColor = RGB(153, 153, 153);
  131. contentLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentTop;
  132. // end modify by huangyibiao
  133. // reasion: handle links in chat content, ananylizing each link
  134. // 提取出文本中的超链接
  135. NSError *error;
  136. NSString *regulaStr = @"((http[s]{0,1}|ftp)://[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)|(www.[a-zA-Z0-9\\.\\-]+\\.([a-zA-Z]{2,4})(:\\d+)?(/[a-zA-Z0-9\\.\\-~!@#$%^&*+?:_/=<>]*)?)";
  137. NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regulaStr
  138. options:NSRegularExpressionCaseInsensitive
  139. error:&error];
  140. NSArray *arrayOfAllMatches = [regex matchesInString:content
  141. options:0
  142. range:NSMakeRange(0, [content length])];
  143. NSMutableAttributedString *attribute = [[NSMutableAttributedString alloc] initWithString:content];
  144. for (NSTextCheckingResult *match in arrayOfAllMatches) {
  145. NSString *substringForMatch = [content substringWithRange:match.range];
  146. [attribute addAttribute:(NSString *)kCTFontAttributeName value:(id)contentLabel.font range:match.range];
  147. [attribute addAttribute:(NSString*)kCTForegroundColorAttributeName
  148. value:(id)[[UIColor blueColor] CGColor]
  149. range:match.range];
  150. [contentLabel addLinkToURL:[NSURL URLWithString:substringForMatch] withRange:match.range];
  151. }
  152. //文本增加长按手势
  153. contentLabel.userInteractionEnabled = YES;
  154. contentLabel.textColor = RGB(153, 153, 153);
  155. UILongPressGestureRecognizer *longTap = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressText:)];
  156. [contentLabel addGestureRecognizer:longTap];
  157. contentLabel.frame = CGRectMake(0, 0, finalSize.width, finalSize.height);
  158. bodyViewAddHight = 0;
  159. }
  160. //图片
  161. if (_imgArray == nil) {
  162. _imgArray = [[NSMutableArray alloc]init];
  163. }
  164. [_imgArray removeAllObjects];
  165. if ([_data.type isEqualToString:@"imagetext"] || [_data.type isEqualToString:@"red_photo"])
  166. {
  167. [_imgArray addObjectsFromArray:_data.images];
  168. }else
  169. {
  170. if (_data.photo_image)
  171. {
  172. [_imgArray addObject:_data.photo_image];
  173. }
  174. }
  175. if (_imgViewArray == nil) {
  176. _imgViewArray = [[NSMutableArray alloc]init];
  177. }
  178. [_imgViewArray removeAllObjects];
  179. CGFloat fromY = contentLabel == nil?0:contentLabel.frame.size.height+10;
  180. if ([_data.type isEqualToString:@"imagetext"] || [_data.type isEqualToString:@"red_photo"])
  181. {
  182. if ([_imgArray count] == 1) {
  183. UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, fromY, 200, 200)];
  184. imageView.tag =100*_row+0;
  185. imageView.userInteractionEnabled = YES;
  186. [imageView sd_setImageWithURL:[NSURL URLWithString:[_imgArray[0] objectForKey:@"url"]]];
  187. [_imgViewArray addObject:imageView];
  188. UITapGestureRecognizer*tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onPressImage:)];
  189. [imageView addGestureRecognizer:tapGesture];
  190. }else if([_imgArray count] == 2){
  191. CGFloat imgWidth = (bodyViewWidth - 2 * kPicDiv)/3;
  192. UIImageView *imageView1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, fromY, imgWidth, imgWidth)];
  193. [imageView1 sd_setImageWithURL:[NSURL URLWithString:[_imgArray[0] objectForKey:@"url"]]];
  194. imageView1.tag =100*_row+0;
  195. imageView1.userInteractionEnabled = YES;
  196. UITapGestureRecognizer*tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onPressImage:)];
  197. [imageView1 addGestureRecognizer:tapGesture];
  198. [_imgViewArray addObject:imageView1];
  199. UIImageView *imageView2 = [[UIImageView alloc]initWithFrame:CGRectMake(imgWidth+kPicDiv,fromY, imgWidth, imgWidth)];
  200. [imageView2 sd_setImageWithURL:[NSURL URLWithString:[_imgArray[1] objectForKey:@"url"]]];
  201. [_imgViewArray addObject:imageView2];
  202. imageView2.tag =100*_row+1;
  203. imageView2.userInteractionEnabled = YES;
  204. UITapGestureRecognizer*tapGesture2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onPressImage:)];
  205. [imageView2 addGestureRecognizer:tapGesture2];
  206. }else if([_imgArray count] == 4){
  207. CGFloat imgWidth = (bodyViewWidth - 2 * kPicDiv)/3;
  208. for (int i=0; i<[_imgArray count]; i++) {
  209. UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((i%2)*(imgWidth+kPicDiv), (i/2)*(imgWidth+kPicDiv) + fromY, imgWidth, imgWidth)];
  210. [imageView sd_setImageWithURL:[NSURL URLWithString:[_imgArray[i] objectForKey:@"url"]]];
  211. imageView.backgroundColor = [UIColor redColor];
  212. imageView.tag =100*_row+i;
  213. imageView.userInteractionEnabled = YES;
  214. [_imgViewArray addObject:imageView];
  215. UITapGestureRecognizer*tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onPressImage:)];
  216. [imageView addGestureRecognizer:tapGesture];
  217. }
  218. }
  219. else{
  220. CGFloat imgWidth = (bodyViewWidth - 2 * kPicDiv)/3;
  221. for (int i=0; i<[_imgArray count]; i++) {
  222. UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake((i%3)*(imgWidth+kPicDiv), (i/3)*(imgWidth+kPicDiv) + fromY, imgWidth, imgWidth)];
  223. [imageView sd_setImageWithURL:[NSURL URLWithString:[_imgArray[i] objectForKey:@"url"]]];
  224. imageView.tag = 100*_row+i;
  225. [_imgViewArray addObject:imageView];
  226. imageView.userInteractionEnabled = YES;
  227. UITapGestureRecognizer*tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onPressImage:)];
  228. [imageView addGestureRecognizer:tapGesture];
  229. }
  230. }
  231. }else if ([_data.type isEqualToString:@"goods"] || [_data.type isEqualToString:@"photo"])
  232. {
  233. if ([_imgArray count])
  234. {
  235. UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, fromY, 200, 200)];
  236. imageView.tag =100*_row+0;
  237. imageView.userInteractionEnabled = YES;
  238. imageView.contentMode = UIViewContentModeScaleAspectFill;
  239. imageView.clipsToBounds = YES;
  240. [imageView sd_setImageWithURL:[NSURL URLWithString:_imgArray[0]]];
  241. if ([_data.type isEqualToString:@"photo"])
  242. {
  243. //写真图
  244. UIImageView *topImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
  245. topImgView.userInteractionEnabled = YES;
  246. topImgView.image = [UIImage imageNamed:@"fw_personCenter_photoAlbum"];
  247. [imageView addSubview:topImgView];
  248. //写真的张数
  249. UILabel *numLabel = [[UILabel alloc]initWithFrame:CGRectMake(150, 6, 44, 20)];
  250. numLabel.backgroundColor = kBlackColor;
  251. numLabel.layer.cornerRadius = 10;
  252. numLabel.layer.masksToBounds = YES;
  253. numLabel.alpha = 0.5;
  254. numLabel.textColor = kWhiteColor;
  255. numLabel.font = [UIFont systemFontOfSize:11];
  256. numLabel.text = _data.images_count;
  257. numLabel.textAlignment = NSTextAlignmentCenter;
  258. [imageView addSubview:numLabel];
  259. UIImageView *rimView1 = [[UIImageView alloc]initWithFrame:CGRectMake(6, fromY-6, 200, 200)];
  260. rimView1.layer.borderWidth = 1;
  261. rimView1.layer.borderColor = kAppSpaceColor2.CGColor;
  262. rimView1.backgroundColor = kWhiteColor;
  263. UIImageView *rimView2 = [[UIImageView alloc]initWithFrame:CGRectMake(3, fromY-3, 200, 200)];
  264. rimView2.layer.borderWidth = 1;
  265. rimView2.layer.borderColor = kAppSpaceColor2.CGColor;
  266. rimView2.backgroundColor = kWhiteColor;
  267. [_imgViewArray addObject:rimView1];
  268. [_imgViewArray addObject:rimView2];
  269. }
  270. [_imgViewArray addObject:imageView];
  271. UITapGestureRecognizer*tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onPressImage:)];
  272. [imageView addGestureRecognizer:tapGesture];
  273. }
  274. }else if ([_data.type isEqualToString:@"video"])//视频动态
  275. {
  276. if ([_imgArray count])
  277. {
  278. UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, fromY, kScreenW-130, ((kScreenW-130)*14)/25)];
  279. //UIImageView *imageView = [[UIImageView alloc]init];
  280. imageView.tag = 100*_row+0;
  281. imageView.userInteractionEnabled = YES;
  282. imageView.contentMode = UIViewContentModeScaleAspectFill;
  283. imageView.clipsToBounds = YES;
  284. [imageView sd_setImageWithURL:[NSURL URLWithString:_imgArray[0]]];
  285. [_imgViewArray addObject:imageView];
  286. //UITapGestureRecognizer*tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(onPressImage:)];
  287. //[imageView addGestureRecognizer:tapGesture];
  288. UIImageView *playImgView = [[UIImageView alloc]initWithFrame:CGRectMake(imageView.size.width/2 -20, imageView.size.height/2 -20, 40, 40)];
  289. playImgView.userInteractionEnabled = YES;
  290. playImgView.tag = 100*_row+0;
  291. playImgView.image = [UIImage imageNamed:@"fw_personCenter_play"];
  292. [imageView addSubview:playImgView];
  293. UITapGestureRecognizer*playGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(playPressImage:)];
  294. [imageView addGestureRecognizer:playGesture];
  295. }
  296. }
  297. CGFloat lastViewHight;
  298. if (_imgViewArray.count)
  299. {
  300. UIImageView *lastView = [_imgViewArray objectAtIndex:([_imgViewArray count]-1) ];
  301. lastViewHight = lastView.frame.size.height + lastView.frame.origin.y;
  302. }else
  303. {
  304. lastViewHight = contentLabel.frame.size.height + contentLabel.frame.origin.y;
  305. }
  306. //地址
  307. self.placeLabel = [[UILabel alloc]init];
  308. self.placeLabel.textColor = RGB(153, 153, 153);
  309. self.placeLabel.font = [UIFont systemFontOfSize:11];
  310. if ([_data.weibo_place length])
  311. {
  312. self.placeLabel.frame = CGRectMake(0, lastViewHight+5, kScreenW-75, 20);
  313. self.placeLabel.text = _data.weibo_place;
  314. }else
  315. {
  316. self.placeLabel.frame = CGRectMake(0, lastViewHight, kScreenW-75, 0);
  317. }
  318. //红包
  319. self.redbagLabel = [[UILabel alloc]init];
  320. self.redbagLabel.textColor = kAppGrayColor1;
  321. self.redbagLabel.font = [UIFont systemFontOfSize:11];
  322. if ([_data.type isEqualToString:@"red_photo"])
  323. {
  324. self.redbagLabel.frame = CGRectMake(0, CGRectGetMaxY(self.placeLabel.frame)+5, kScreenW-75, 20);
  325. self.redbagLabel.text = [NSString stringWithFormat:ASLocalizedString(@"%d人看了照片,共收入%.2f元"),[_data.red_count intValue],[_data.red_count floatValue]*[_data.price floatValue]];
  326. }else
  327. {
  328. self.redbagLabel.frame = CGRectMake(0, CGRectGetMaxY(self.placeLabel.frame), kScreenW-75, 0);
  329. }
  330. CGFloat bodyHight = self.redbagLabel.frame.size.height + self.redbagLabel.frame.origin.y;
  331. self.bodyView = nil;
  332. self.bodyView = [[UIView alloc]initWithFrame:CGRectMake(_nameLabel.frame.origin.x, _nameLabel.frame.origin.y + _nameLabel.frame.size.height + 10, bodyViewWidth, bodyHight)];
  333. [self.contentView addSubview:self.bodyView];
  334. if(contentLabel != nil){
  335. [self.bodyView addSubview:contentLabel];
  336. }
  337. for (UIImageView *iv in _imgViewArray) {
  338. [self.bodyView addSubview:iv];
  339. }
  340. if(self.placeLabel != nil){
  341. [self.bodyView addSubview:self.placeLabel];
  342. }
  343. if(self.redbagLabel != nil){
  344. [self.bodyView addSubview:self.redbagLabel];
  345. }
  346. }
  347. #pragma mark 底部
  348. - (void)setZanReplyBar
  349. {
  350. _zanBarView = [[UIView alloc]initWithFrame:CGRectMake(0, _bodyView.frame.size.height + _bodyView.frame.origin.y, kScreenW, 46)];
  351. #pragma mark 点赞
  352. UIImageView *zanImgView = [[UIImageView alloc]initWithFrame:CGRectMake(65, 18, 12, 10)];
  353. zanImgView.image = [UIImage imageNamed:@"fw_personCenter_noZan"];
  354. [_zanBarView addSubview:zanImgView];
  355. UILabel *zanLabel = [[UILabel alloc]initWithFrame:CGRectMake(zanImgView.frame.size.width+zanImgView.origin.x+5, 13, 50, 20)];
  356. zanLabel.textColor = RGB(153, 153, 153);
  357. zanLabel.font = [UIFont systemFontOfSize:12];
  358. [_zanBarView addSubview:zanLabel];
  359. if ([_data.type isEqualToString:@"goods"])
  360. {
  361. zanLabel.text = ASLocalizedString(@"我要购买");
  362. zanImgView.image = [UIImage imageNamed:@"fw_personCenter_buyCar"];
  363. zanLabel.textColor = kAppGrayColor1;
  364. UIButton *buyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  365. buyBtn.frame = CGRectMake(65, 0, 60, 46);
  366. buyBtn.backgroundColor = kClearColor;
  367. buyBtn.tag = _row*100+4;
  368. [buyBtn addTarget:self action:@selector(zanBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  369. //[_zanBarView addSubview:buyBtn];
  370. [self.contentView addSubview:_zanBarView];
  371. }else
  372. {
  373. zanLabel.text = _data.digg_count;
  374. UIButton *zanBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  375. zanBtn.frame = CGRectMake(65, 0, 60, 46);
  376. zanBtn.backgroundColor = kClearColor;
  377. zanBtn.tag = _row*100+0;
  378. [zanBtn addTarget:self action:@selector(zanBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  379. [_zanBarView addSubview:zanBtn];
  380. [self.contentView addSubview:_zanBarView];
  381. if (_data.has_digg == 1)//已经点赞过了显示红色
  382. {
  383. zanImgView.image = [UIImage imageNamed:@"fw_personCenter_zan"];
  384. zanLabel.textColor = kAppGrayColor1;
  385. }
  386. }
  387. #pragma mark 评论
  388. UIImageView *commentImgView = [[UIImageView alloc]initWithFrame:CGRectMake(zanLabel.frame.size.width+zanLabel.origin.x, 18, 13, 10)];
  389. commentImgView.image = [UIImage imageNamed:@"fw_personCenter_comment"];
  390. [_zanBarView addSubview:commentImgView];
  391. UILabel *commentLabel = [[UILabel alloc]initWithFrame:CGRectMake(commentImgView.frame.size.width+commentImgView.origin.x+5, 13, 50, 20)];
  392. commentLabel.textColor = RGB(153, 153, 153);
  393. commentLabel.font = [UIFont systemFontOfSize:12];
  394. commentLabel.text = _data.comment_count;
  395. [_zanBarView addSubview:commentLabel];
  396. UIButton *commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  397. commentBtn.frame = CGRectMake(zanLabel.frame.size.width+zanLabel.origin.x, 0, 50, 46);
  398. commentBtn.backgroundColor = kClearColor;
  399. commentBtn.tag = _row*100+1;
  400. [commentBtn addTarget:self action:@selector(zanBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  401. [_zanBarView addSubview:commentBtn];
  402. commentBtn.hidden = YES;
  403. #pragma mark 播放
  404. UIImageView *playImgView = [[UIImageView alloc]initWithFrame:CGRectMake(commentLabel.frame.size.width+commentLabel.origin.x, 18, 13, 10)];
  405. playImgView.image = [UIImage imageNamed:@"fw_personCenter_playNum"];
  406. [_zanBarView addSubview:playImgView];
  407. UILabel *playLabel = [[UILabel alloc]initWithFrame:CGRectMake(playImgView.frame.size.width+playImgView.origin.x+5, 13, 50, 20)];
  408. playLabel.textColor = RGB(153, 153, 153);
  409. playLabel.font = [UIFont systemFontOfSize:12];
  410. playLabel.text = _data.video_count;
  411. [_zanBarView addSubview:playLabel];
  412. UIButton *playBtn;
  413. if ([_data.type isEqualToString:@"red_photo"])
  414. {
  415. playLabel.text = _data.red_count;
  416. playLabel.textColor = kAppGrayColor1;
  417. playImgView.image = [UIImage imageNamed:@"fw_personCenter_redBag"];
  418. UIButton *redBagBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  419. redBagBtn.frame = CGRectMake(commentLabel.frame.size.width+commentLabel.origin.x, 0,40, 46);
  420. redBagBtn.backgroundColor = kClearColor;
  421. redBagBtn.tag = _row*100+5;
  422. [redBagBtn addTarget:self action:@selector(zanBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  423. [_zanBarView addSubview:redBagBtn];
  424. redBagBtn.hidden = YES;
  425. }else
  426. {
  427. playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  428. playBtn.frame = CGRectMake(commentLabel.frame.size.width+commentLabel.origin.x, 0,40, 46);
  429. playBtn.backgroundColor = kClearColor;
  430. playBtn.tag = _row*100+2;
  431. [playBtn addTarget:self action:@selector(zanBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  432. [_zanBarView addSubview:playBtn];
  433. playBtn.hidden = YES;
  434. }
  435. if ([_data.type isEqualToString:@"goods"] )
  436. {
  437. commentImgView.hidden = YES;
  438. commentLabel.hidden = YES;
  439. commentBtn.hidden = YES;
  440. playImgView.hidden = YES;
  441. playLabel.hidden = YES;
  442. playBtn.hidden = YES;
  443. }
  444. if ([_data.type isEqualToString:@"photo"] || [_data.type isEqualToString:@"imagetext"])
  445. {
  446. playImgView.hidden = YES;
  447. playLabel.hidden = YES;
  448. playBtn.hidden = YES;
  449. }
  450. #pragma mark 更多
  451. UIImageView *moreImgView = [[UIImageView alloc]initWithFrame:CGRectMake(kScreenW-37, 20, 22, 5)];
  452. moreImgView.image = [UIImage imageNamed:@"fw_personCenter_more"];
  453. [_zanBarView addSubview:moreImgView];
  454. UIButton *moreBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  455. moreBtn.frame = CGRectMake(kScreenW-40, 0, 40, 46);
  456. moreBtn.backgroundColor = kClearColor;
  457. moreBtn.tag = _row*100+3;
  458. [moreBtn addTarget:self action:@selector(zanBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  459. [_zanBarView addSubview:moreBtn];
  460. UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 45, kScreenW, 1)];
  461. lineView.backgroundColor = kAppSpaceColor2;
  462. [_zanBarView addSubview:lineView];
  463. }
  464. - (CGSize)sizeThatFits:(CGSize)size
  465. {
  466. return CGSizeMake(kScreenW, _zanBarView.frame.size.height + _zanBarView.frame.origin.y+10);
  467. }
  468. #pragma mark 点赞之类的操作
  469. - (void)zanBtnClick:(UIButton *)button
  470. {
  471. NSLog(@"tag==%d",(int)button.tag);
  472. if (self.DDelegate && [self.DDelegate respondsToSelector:@selector(onPressZanBtnOnDynamicCell:andTag:)])
  473. {
  474. [self.DDelegate onPressZanBtnOnDynamicCell:self andTag:(int)button.tag];
  475. }
  476. }
  477. #pragma mark 图片的点击事件
  478. - (void)onPressImage:(UITapGestureRecognizer *)tap
  479. {
  480. if (self.DDelegate && [self.DDelegate respondsToSelector:@selector(onPressImageView:andTag:)])
  481. {
  482. [self.DDelegate onPressImageView:self andTag:(int)tap.view.tag ];
  483. }
  484. }
  485. #pragma mark 播放视频的点击事件
  486. - (void)playPressImage:(UITapGestureRecognizer *)tap
  487. {
  488. if (self.DDelegate && [self.DDelegate respondsToSelector:@selector(onPressImageView:andTag:)])
  489. {
  490. [self.DDelegate onPressImageView:self andTag:(int)tap.view.tag];
  491. }
  492. }
  493. - (void)headTap:(UITapGestureRecognizer *)tap
  494. {
  495. if (self.DDelegate && [self.DDelegate respondsToSelector:@selector(onPressImageView:andTag:)])
  496. {
  497. [self.DDelegate onPressImageView:self andTag:(int)tap.view.tag];
  498. }
  499. }
  500. #pragma mark 文字的复制事件
  501. - (void)longPressText:(UILongPressGestureRecognizer *)tap
  502. {
  503. }
  504. @end