YOUPAIZYDynamicVideoCell.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // YOUPAIZYDynamicVideoCell.m
  3. // VQU
  4. //
  5. // Created by Elaine on 2020/11/17.
  6. // Copyright © 2020 leo. All rights reserved.
  7. //
  8. #import "YOUPAIZYDynamicVideoCell.h"
  9. @interface YOUPAIZYDynamicVideoCell()
  10. //@property(nonatomic,strong)UILabel *likeCountL;
  11. //@property(nonatomic,strong)UILabel *giltCountL;
  12. @property (nonatomic,weak) UIButton *youpaiplikeBtn;
  13. @property (nonatomic,weak) UILabel *youpaiptitleL;
  14. @end
  15. @implementation YOUPAIZYDynamicVideoCell
  16. -(instancetype)initWithFrame:(CGRect)frame
  17. {
  18. self = [super initWithFrame:frame];
  19. if (self){
  20. [self youpaifinitUI];
  21. }
  22. return self;
  23. }
  24. - (void)youpaifinitUI{
  25. self.layer.cornerRadius = 5.0f;
  26. self.layer.masksToBounds = YES;
  27. self.backgroundColor = [UIColor clearColor];
  28. self.youpaipcoverImgV = [[UIImageView alloc]initWithFrame:self.contentView.bounds];
  29. self.youpaipcoverImgV.contentMode = UIViewContentModeScaleAspectFill;
  30. self.youpaipcoverImgV.layer.masksToBounds = YES;
  31. self.youpaipcoverImgV.layer.cornerRadius = 5.0f;
  32. [self.contentView addSubview:self.youpaipcoverImgV];
  33. UIView *bottomBkgView = [[UIView alloc]initWithFrame:CGRectMake(0, self.frame.size.height-45.0f, self.frame.size.width, 45.0f)];
  34. CAGradientLayer *gradientLayerBot = [CAGradientLayer layer];
  35. gradientLayerBot.frame = bottomBkgView.bounds;
  36. //设置渐变颜色数组,可以加透明度的渐变
  37. gradientLayerBot.colors = @[(__bridge id)HexColorFromRGBA(0x000000, 0.001).CGColor,(__bridge id)HexColorFromRGBA(0x000000, 0.3).CGColor];
  38. //设置渐变区域的起始和终止位置(范围为0-1)
  39. gradientLayerBot.startPoint = CGPointMake(0, 0);
  40. gradientLayerBot.endPoint = CGPointMake(0, 1);
  41. [bottomBkgView.layer addSublayer:gradientLayerBot];
  42. [self.contentView addSubview:bottomBkgView];
  43. UIImageView *playImgV = [[UIImageView alloc] init];
  44. playImgV.image = [UIImage imageNamed:@"vqu_images_ic_p_vqu_images_D_video_play"];
  45. [self.contentView addSubview:playImgV];
  46. [playImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  47. make.center.equalTo(self.contentView);
  48. make.size.mas_offset(CGSizeMake(34.0f, 34.0f));
  49. }];
  50. UIButton *likeBtn = [[UIButton alloc]init];
  51. likeBtn.titleLabel.font = LCFont(10);
  52. [likeBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  53. [likeBtn setImage:[UIImage imageNamed:@"vqu_images_ic_p_video_like_select"] forState:UIControlStateSelected];
  54. [likeBtn setImage:[UIImage imageNamed:@"vqu_images_ic_p_video_like_normal"] forState:UIControlStateNormal];
  55. [likeBtn addTarget:self action:@selector(youpaiflikeClick) forControlEvents:(UIControlEventTouchUpInside)];
  56. [bottomBkgView addSubview:likeBtn];
  57. self.youpaiplikeBtn = likeBtn;
  58. [likeBtn makeConstraints:^(MASConstraintMaker *make) {
  59. make.left.offset(8.0f);
  60. make.top.offset(0);
  61. make.height.equalTo(25.0f);
  62. }];
  63. UILabel *titleL = [[UILabel alloc]init];
  64. titleL.textColor = HexColorFromRGB(0xFFFFFF);
  65. titleL.textAlignment = NSTextAlignmentLeft;
  66. titleL.font = LCFont(12);
  67. [bottomBkgView addSubview:titleL];
  68. self.youpaiptitleL = titleL;
  69. [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  70. make.left.offset(8.0f);
  71. make.right.offset(-8.0f);
  72. make.top.equalTo(likeBtn.mas_bottom).offset(0.0f);
  73. }];
  74. }
  75. -(void)setYoupaipmodel:(YOUPAIZYVideoModel *)model{
  76. _youpaipmodel = model;
  77. [self.youpaipcoverImgV sd_setImageWithURL:[NSURL URLWithString:model.youpaipcover_url]];
  78. [self.youpaiplikeBtn setTitle:[NSString stringWithFormat:@"%zd",model.youpaiplike_count] forState:(UIControlStateNormal)];
  79. if (model.youpaipis_like) {
  80. self.youpaiplikeBtn.selected = YES;
  81. }else{
  82. self.youpaiplikeBtn.selected = NO;
  83. }
  84. self.youpaiptitleL.text= model.youpaipcontent;
  85. }
  86. - (void)youpaiflikeClick{
  87. [LCHttpHelper requestWithURLString:TrendsLike parameters:@{@"vt_id":self.youpaipmodel.youpaipvideoId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  88. NSDictionary* dict = (NSDictionary*)responseObject;
  89. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  90. if (code==0) {//成功
  91. NSInteger type = [[[dict objectForKey:@"data"] objectForKey:@"type"] integerValue];
  92. NSString *like_count = [NSString stringWithFormat:@"%@",[[dict objectForKey:@"data"] objectForKey:@"like_count"]];
  93. self.youpaipmodel.youpaiplike_count = [like_count integerValue];
  94. self.youpaipmodel.youpaipis_like = type;
  95. [self.youpaiplikeBtn setTitle:[NSString stringWithFormat:@"%zd",self.youpaipmodel.youpaiplike_count] forState:(UIControlStateNormal)];
  96. if (self.youpaipmodel.youpaipis_like) {
  97. self.youpaiplikeBtn.selected = YES;
  98. }else{
  99. self.youpaiplikeBtn.selected = NO;
  100. }
  101. }
  102. } failure:^(NSError *error) {
  103. }];
  104. }
  105. @end