new_bgmitemCell.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // new_bgmitemCell.m
  3. // BuguLive
  4. //
  5. // Created by bugu on 2019/5/25.
  6. // Copyright © 2019年 xfg. All rights reserved.
  7. //
  8. #import "new_bgmitemCell.h"
  9. @implementation new_bgmitemCell
  10. {
  11. UIButton *Collection;
  12. UIImageView *icon,*isplaying;
  13. UIButton *UseBTn;
  14. UILabel *music_nameLa,*music_author;
  15. }
  16. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  17. {
  18. self =[super initWithStyle:style reuseIdentifier:reuseIdentifier];
  19. self.layer.masksToBounds =YES;
  20. [self drawsubviews];
  21. return self;
  22. }
  23. - (void)setModel:(music_obj *)model
  24. {
  25. _model =model;
  26. [icon sd_setImageWithURL:[NSURL URLWithString:model.cover]];
  27. music_nameLa.text =model.music_name;
  28. music_author.text =model.music_author;
  29. if (model.is_collection == 1)
  30. {
  31. Collection.selected =YES;
  32. }else
  33. {
  34. Collection.selected =NO;
  35. }
  36. if (model.isselect)
  37. {
  38. isplaying.image =[UIImage imageNamed:@"new_bgm_stop"];
  39. }else
  40. {
  41. isplaying.image =[UIImage imageNamed:@"new_bgm_play"];
  42. }
  43. }
  44. - (void)sureuseAction
  45. {
  46. if ([_delegate respondsToSelector:@selector(selectItem:)])
  47. {
  48. [_delegate selectItem:_model];
  49. }
  50. }
  51. - (void)docollection
  52. {
  53. if ([_delegate respondsToSelector:@selector(doCollection:)])
  54. {
  55. [_delegate doCollection:_model];
  56. }
  57. }
  58. -(void)drawsubviews
  59. {
  60. //未展开140
  61. if (!icon)
  62. {
  63. __weak typeof(self)weakself =self;
  64. icon =[[UIImageView alloc]init];
  65. [self addSubview:icon];
  66. [icon mas_makeConstraints:^(MASConstraintMaker *make) {
  67. make.left.equalTo(weakself).offset(30);
  68. make.top.equalTo(weakself).offset(14);
  69. make.width.height.equalTo(@(112 ));
  70. }];
  71. icon.contentMode =UIViewContentModeScaleAspectFill;
  72. isplaying=[[UIImageView alloc]init];
  73. [self addSubview:isplaying];
  74. [isplaying mas_makeConstraints:^(MASConstraintMaker *make) {
  75. make.center.equalTo(icon);
  76. make.width.height.equalTo(icon).multipliedBy(0.4);
  77. }];
  78. isplaying.image =[UIImage imageNamed:@"new_bgm_play"];
  79. isplaying.contentMode =UIViewContentModeScaleAspectFit;
  80. music_nameLa =[UILabel new];
  81. [self addSubview:music_nameLa];
  82. [music_nameLa mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.left.equalTo(icon.mas_right).offset(30);
  84. make.bottom.equalTo(icon.mas_centerY);
  85. make.height.equalTo(@(42));
  86. make.right.equalTo(weakself).offset(-75);
  87. }];
  88. music_nameLa.font =[UIFont fontWithName:@"Helvetica-Bold" size:16.];
  89. music_nameLa.textColor =kBlackColor;
  90. music_author =[UILabel new];
  91. [self addSubview:music_author];
  92. [music_author mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.left.equalTo(icon.mas_right).offset(30);
  94. make.top.equalTo(icon.mas_centerY);
  95. make.height.equalTo(@(42));
  96. make.right.equalTo(weakself).offset(-75);
  97. }];
  98. music_author.font =[UIFont fontWithName:@"Helvetica" size:14.];
  99. music_author.textColor =kGrayColor;
  100. Collection =[[UIButton alloc]init];
  101. [self addSubview:Collection];
  102. [Collection mas_makeConstraints:^(MASConstraintMaker *make) {
  103. make.right.equalTo(weakself).offset(-30);
  104. make.centerY.equalTo(icon);
  105. make.width.height.equalTo(@(44 ));
  106. }];
  107. [Collection setImage:[UIImage imageNamed:@"new_bgm_collection"] forState:0];
  108. [Collection setImage:[UIImage imageNamed:@"new_bgm_collectionSelect"] forState:UIControlStateSelected];
  109. [Collection addTarget:self action:@selector(docollection) forControlEvents:UIControlEventTouchUpInside];
  110. UseBTn=[[UIButton alloc]init];
  111. [self addSubview:UseBTn];
  112. [UseBTn mas_makeConstraints:^(MASConstraintMaker *make) {
  113. make.left.equalTo(weakself).offset(30);
  114. make.right.equalTo(weakself).offset(-30);
  115. make.top.equalTo(icon.mas_bottom).offset(24);
  116. make.height.equalTo(@(82 ));
  117. }];
  118. UseBTn.layer.cornerRadius =41;
  119. UseBTn.backgroundColor =UIColorFromRGB(0xe8465d);
  120. [UseBTn setTitle:ASLocalizedString(@"确认使用")forState:0];
  121. [UseBTn setTitleColor:kWhiteColor forState:0];
  122. UseBTn.titleLabel.font =[UIFont systemFontOfSize:15.];
  123. [UseBTn addTarget:self action:@selector(sureuseAction) forControlEvents:UIControlEventTouchUpInside];
  124. }
  125. }
  126. - (void)awakeFromNib {
  127. [super awakeFromNib];
  128. // Initialization code
  129. }
  130. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  131. [super setSelected:selected animated:animated];
  132. // Configure the view for the selected state
  133. }
  134. @end