TCMusicCollectionCell.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // TCMusicCollectionCell.m
  3. // DeviceManageIOSApp
  4. //
  5. // Created by rushanting on 2017/5/15.
  6. // Copyright © 2017年 tencent. All rights reserved.
  7. //
  8. #import "TCMusicCollectionCell.h"
  9. #import "ColorMacro.h"
  10. //#import "UIView+AdditionsX12.h"
  11. @implementation TCMusicInfo
  12. @end
  13. @implementation TCMusicCollectionCell
  14. {
  15. }
  16. - (id)initWithFrame:(CGRect)frame
  17. {
  18. if (self = [super initWithFrame:frame]) {
  19. self.backgroundColor = UIColorFromRGB(0x181818);
  20. _iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"voice_nor"]];
  21. [self.contentView addSubview:_iconView];
  22. _songNameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  23. _songNameLabel.text = YZMsg(@"歌名");
  24. _songNameLabel.textColor = UIColorFromRGB(0x777777);
  25. _songNameLabel.textAlignment = NSTextAlignmentCenter;
  26. _songNameLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:10];
  27. //_songNameLabel.font = [UIFont systemFontOfSize:10];
  28. _songNameLabel.numberOfLines = 2;
  29. _songNameLabel.lineBreakMode = NSLineBreakByWordWrapping;
  30. [self.contentView addSubview:_songNameLabel];
  31. _authorNameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  32. _authorNameLabel.textColor = UIColorFromRGB(0x555555);
  33. _authorNameLabel.text = YZMsg(@"作者");
  34. _authorNameLabel.textAlignment = NSTextAlignmentCenter;
  35. _authorNameLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:10];
  36. //_authorNameLabel.font = [UIFont systemFontOfSize:10];
  37. [self.contentView addSubview:_authorNameLabel];
  38. _deleteBtn = [UIButton new];
  39. _deleteBtn.backgroundColor = UIColor.darkGrayColor;
  40. _deleteBtn.alpha = 0.7;
  41. [_deleteBtn setImage:[UIImage imageNamed:@"video_record_close"] forState:UIControlStateNormal];
  42. [self.contentView addSubview:_deleteBtn];
  43. _deleteBtn.hidden = YES;
  44. }
  45. return self;
  46. }
  47. - (void)layoutSubviews
  48. {
  49. [super layoutSubviews];
  50. _iconView.center = CGPointMake(self.width / 2, 15 + _iconView.image.size.height / 2);
  51. [_songNameLabel sizeToFit];
  52. _songNameLabel.frame = CGRectMake(5, _iconView.bottom + 10, self.width - 10, _songNameLabel.height);
  53. [_authorNameLabel sizeToFit];
  54. _authorNameLabel.frame = CGRectMake(10, self.height - 10 - 10, self.width - 20, 10);
  55. _deleteBtn.frame = CGRectMake(0, 0, 20, 20);
  56. }
  57. - (void)setSelected:(BOOL)selected
  58. {
  59. //本地音频的按钮
  60. if (_authorNameLabel.hidden) {
  61. return;
  62. }
  63. if (!selected) {
  64. _iconView.image = [UIImage imageNamed:@"voice_nor"];
  65. _songNameLabel.textColor = UIColorFromRGB(0x777777);
  66. _authorNameLabel.textColor = UIColorFromRGB(0x555555);
  67. self.layer.borderColor = UIColorFromRGB(0x181818).CGColor;
  68. } else {
  69. _iconView.image = [UIImage imageNamed:@"voice_pressed"];
  70. _songNameLabel.textColor = Pink_Cor;//UIColorFromRGB(0x0accac);
  71. _authorNameLabel.textColor = Pink_Cor;//UIColorFromRGB(0x0accac);
  72. self.layer.borderWidth = 1;
  73. self.layer.borderColor = Pink_Cor.CGColor;//UIColorFromRGB(0x0accac).CGColor;
  74. }
  75. }
  76. - (void)setModel:(TCMusicInfo *)model
  77. {
  78. _songNameLabel.text = model.soneName;
  79. if (_songNameLabel.text.length > 0) {
  80. NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:_songNameLabel.text];
  81. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  82. [paragraphStyle setLineSpacing:11];
  83. [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [_songNameLabel.text length])];
  84. _songNameLabel.attributedText = attributedString;
  85. _songNameLabel.textAlignment = NSTextAlignmentCenter;
  86. }
  87. _authorNameLabel.text = model.singerName;
  88. }
  89. #pragma mark - UI event handle
  90. @end