Netease-Music-Demo by sss
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SideBarView.swift 2.1KB

3 lat temu
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // SideBarView.swift
  3. // wyy
  4. //
  5. // Created by 施书顺 on 2021/3/6.
  6. //
  7. import UIKit
  8. import SnapKit
  9. class SideBarView: UIView, UITableViewDataSource, UITableViewDelegate {
  10. struct SideBarCellData {
  11. var imageName: String
  12. var title: String
  13. }
  14. let centerTableView = UITableView()
  15. var centerTableData = [SideBarCellData(imageName: "discover", title: "消息中心"),
  16. SideBarCellData(imageName: "discover", title: "消息中心"),
  17. SideBarCellData(imageName: "discover", title: "消息中心")]
  18. init(){
  19. super.init(frame: CGRect(x: 0, y: 0, width: 300, height: 1000))
  20. addSubview(centerTableView)
  21. centerTableView.dataSource = self
  22. centerTableView.delegate = self
  23. centerTableView.snp.makeConstraints { make in
  24. make.top.equalTo(20)
  25. make.centerX.equalToSuperview()
  26. make.width.equalTo(300)
  27. make.height.equalTo(800)
  28. }
  29. centerTableView.reloadData()
  30. }
  31. required init?(coder: NSCoder) {
  32. fatalError("init(coder:) has not been implemented")
  33. }
  34. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  35. switch tableView {
  36. case centerTableView:
  37. return centerTableData.count
  38. default:
  39. return 0
  40. }
  41. }
  42. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  43. let cellID = "sideBarCell"
  44. var cell: SideBarCell? = tableView.dequeueReusableCell(withIdentifier: cellID) as? SideBarCell
  45. if cell == nil {
  46. cell = SideBarCell(style: .subtitle, reuseIdentifier: cellID)
  47. }
  48. var data: SideBarCellData
  49. switch tableView {
  50. case centerTableView:
  51. data = centerTableData[indexPath.row]
  52. default:
  53. data = centerTableData[indexPath.row]
  54. }
  55. cell?.iconImageView.image = UIImage(named: data.imageName)
  56. cell?.titleLabel.text = data.title
  57. print(111)
  58. return cell!
  59. }
  60. }