Netease-Music-Demo by sss
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AlbumButton.swift 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //
  2. // AlbumButton.swift
  3. // wyy
  4. //
  5. // Created by 施书顺 on 2021/3/5.
  6. //
  7. import UIKit
  8. import SnapKit
  9. class AlbumButton: UIButton {
  10. let spacing : CGFloat = 5.0
  11. let label = UILabel()
  12. var count : Int = 0
  13. let countLabel = UILabel()
  14. init(imageName: String, title: String, count: Int){
  15. super.init(frame: CGRect.zero)
  16. self.count = count
  17. snp.makeConstraints{ make in
  18. make.width.equalTo(100)
  19. make.height.equalTo(100)
  20. }
  21. setImage(UIImage(named: imageName), for: .normal)
  22. imageView?.layer.cornerRadius = 10
  23. addSubview(label)
  24. label.text = title
  25. label.font = UIFont.systemFont(ofSize: 13)
  26. label.numberOfLines = 2
  27. label.lineBreakMode = .byWordWrapping
  28. label.textAlignment = .left
  29. label.snp.makeConstraints{ make in
  30. make.top.equalTo(105)
  31. make.left.equalTo(5)
  32. make.width.equalTo(100)
  33. }
  34. countLabel.text = "▷ \(count)"
  35. countLabel.font = UIFont.systemFont(ofSize: 12)
  36. countLabel.textColor = UIColor.white
  37. countLabel.textAlignment = .right
  38. addSubview(countLabel)
  39. countLabel.snp.makeConstraints{ make in
  40. make.top.equalTo(3)
  41. make.right.equalToSuperview().offset(-8)
  42. }
  43. let blurEffect = UIBlurEffect(style: .light)
  44. let blurEffectView = UIVisualEffectView(effect: blurEffect)
  45. blurEffectView.layer.cornerRadius = 6
  46. blurEffectView.clipsToBounds = true
  47. addSubview(blurEffectView)
  48. blurEffectView.snp.makeConstraints{ make in
  49. make.top.equalTo(3)
  50. make.right.equalToSuperview().offset(-5)
  51. make.width.equalTo(countLabel.snp.width).offset(6)
  52. make.height.equalTo(countLabel.snp.height).offset(2)
  53. }
  54. bringSubviewToFront(countLabel)
  55. }
  56. required init?(coder: NSCoder) {
  57. fatalError("init(coder:) has not been implemented")
  58. }
  59. }