CWOperateItemView.swift 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // CWOperateItemView.swift
  3. // ColorfulWallpaper
  4. //
  5. // Created by ni on 2024/9/19.
  6. //
  7. import Foundation
  8. import UIKit
  9. class CWOperateItemView: UIControl {
  10. lazy var iconView: UIImageView = .simpleImage(imageName: "")
  11. lazy var titleLabel: UILabel = .simpleLabel(text: "", font: .systemFont14, color: .black)
  12. var type: CWOperateType = .like
  13. override init(frame: CGRect) {
  14. super.init(frame: frame)
  15. addChildren()
  16. makeConstraints()
  17. }
  18. convenience init(imgName: String, title: String, type: CWOperateType) {
  19. self.init(frame: .zero)
  20. iconView.image = .init(named: imgName)
  21. titleLabel.text = title
  22. self.type = type
  23. }
  24. func addChildren() {
  25. addSubview(iconView)
  26. addSubview(titleLabel)
  27. }
  28. func makeConstraints() {
  29. iconView.snp.makeConstraints { make in
  30. make.leading.equalToSuperview().offset(16)
  31. make.width.height.equalTo(28)
  32. make.verticalEdges.equalToSuperview().inset(18)
  33. }
  34. titleLabel.snp.makeConstraints { make in
  35. make.leading.equalTo(iconView.snp.trailing).offset(12)
  36. make.trailing.equalToSuperview().offset(-16)
  37. make.centerY.equalTo(iconView)
  38. }
  39. }
  40. required init?(coder: NSCoder) {
  41. fatalError("init(coder:) has not been implemented")
  42. }
  43. }