UGCKitBGMCell.m 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (c) 2019 Tencent. All rights reserved.
  2. #import "UGCKitBGMCell.h"
  3. #import "UGCKitBGMProgressView.h"
  4. @implementation UGCKitBGMCell
  5. {
  6. CGFloat _progress;
  7. UGCKitBGMProgressView *_progressView;
  8. }
  9. - (void)awakeFromNib {
  10. [super awakeFromNib];
  11. [self setSelectionStyle:UITableViewCellSelectionStyleNone];
  12. [self.downLoadBtn setTitle:self.downloadText forState:UIControlStateNormal];
  13. }
  14. -(void) setDownloadProgress:(CGFloat)progress
  15. {
  16. UIImage *image = self.progressButtonBackground;
  17. if (_progressView == nil) {
  18. _progressView = [[UGCKitBGMProgressView alloc] initWithFrame:_downLoadBtn.bounds bgImage:self.progressButtonBackground];
  19. _progressView.label.text = self.downloadingText;
  20. _progressView.label.textColor = [UIColor whiteColor];
  21. _progressView.backgroundColor = [UIColor clearColor];
  22. _progressView.progressBackgroundColor = [UIColor colorWithRed:0.21 green:0.22 blue:0.27 alpha:1.00];
  23. _progressView.translatesAutoresizingMaskIntoConstraints = NO;
  24. [self.contentView addSubview:_progressView];
  25. [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_progressView
  26. attribute:NSLayoutAttributeCenterY
  27. relatedBy:NSLayoutRelationEqual
  28. toItem:self.contentView
  29. attribute:NSLayoutAttributeCenterY
  30. multiplier:1
  31. constant:0]];
  32. [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_progressView
  33. attribute:NSLayoutAttributeHeight
  34. relatedBy:NSLayoutRelationEqual
  35. toItem:_downLoadBtn
  36. attribute:NSLayoutAttributeHeight
  37. multiplier:1
  38. constant:0]];
  39. [self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:_progressView
  40. attribute:NSLayoutAttributeRight
  41. relatedBy:NSLayoutRelationEqual
  42. toItem:self.contentView
  43. attribute:NSLayoutAttributeRight
  44. multiplier:1
  45. constant:-8]];
  46. }
  47. _progress = progress;
  48. _progressView.progress = progress;
  49. if (progress == 1.0) {
  50. [self.downLoadBtn setTitle:self.applyText forState:UIControlStateNormal];
  51. [self.downLoadBtn setBackgroundImage:image forState:UIControlStateNormal];
  52. _progressView.hidden = YES;
  53. } else {
  54. [self.downLoadBtn setTitle:self.downloadText forState:UIControlStateNormal];
  55. [self.downLoadBtn setBackgroundImage:self.downloadButtonBackground forState:UIControlStateNormal];
  56. _progressView.hidden = NO;
  57. }
  58. }
  59. - (void)prepareForReuse
  60. {
  61. [super prepareForReuse];
  62. [self.downLoadBtn setTitle:self.downloadText forState:UIControlStateNormal];
  63. [self.downLoadBtn setBackgroundImage: self.downloadButtonBackground forState:UIControlStateNormal];
  64. }
  65. - (IBAction)download:(id)sender {
  66. [self.delegate onBGMDownLoad:self];
  67. [_downLoadBtn setTitle:self.downloadingText forState:UIControlStateNormal];
  68. _downLoadBtn.titleLabel.alpha = 0.5;
  69. }
  70. @end