KMCloudNoNetworkView.swift 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // KMCloudNoNetworkView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/2/14.
  6. //
  7. import Cocoa
  8. typealias KMCloudNoNetworkViewItemClick = (Int) -> ()
  9. class KMCloudNoNetworkView: NSView {
  10. var imageView = NSImageView()
  11. var titleLabel = NSTextField(labelWithString: "")
  12. var despLabel = NSTextField(labelWithString: "")
  13. var funcButton = NSButton()
  14. var itemClick: KMCloudNoNetworkViewItemClick?
  15. override var isFlipped: Bool {
  16. return true
  17. }
  18. override init(frame frameRect: NSRect) {
  19. super.init(frame: frameRect)
  20. initSubViews()
  21. }
  22. required init?(coder: NSCoder) {
  23. super.init(coder: coder)
  24. initSubViews()
  25. }
  26. public func initSubViews() {
  27. self.addSubview(self.imageView)
  28. self.addSubview(self.titleLabel)
  29. self.addSubview(self.despLabel)
  30. self.addSubview(self.funcButton)
  31. self.titleLabel.alignment = .center
  32. self.titleLabel.stringValue = NSLocalizedString("No network detected", comment: "")
  33. self.despLabel.alignment = .center
  34. self.despLabel.stringValue = NSLocalizedString("To access your files, please connect to the Internet and try again.", comment: "")
  35. self.funcButton.isBordered = false
  36. self.funcButton.wantsLayer = true
  37. self.funcButton.title = NSLocalizedString("Retry", comment: "")
  38. self.funcButton.target = self
  39. self.funcButton.action = #selector(funcButtonAction)
  40. }
  41. override func layout() {
  42. super.layout()
  43. let width: CGFloat = NSWidth(self.bounds)
  44. let imageSize: NSSize = NSMakeSize(80, 80)
  45. self.imageView.frame = NSMakeRect((width-imageSize.width)*0.5, 20, imageSize.width, imageSize.height)
  46. self.titleLabel.frame = NSMakeRect(0, self.imageView.frame.maxY+20, width, 22)
  47. self.despLabel.frame = NSMakeRect(0, self.titleLabel.frame.maxY+2, width, 20)
  48. let buttonSize: NSSize = NSMakeSize(68, 32)
  49. self.funcButton.frame = NSMakeRect((width-buttonSize.width)*0.5, self.despLabel.frame.maxY+8, buttonSize.width, buttonSize.height)
  50. }
  51. @objc func funcButtonAction() {
  52. guard let callback = self.itemClick else {
  53. return
  54. }
  55. callback(1)
  56. }
  57. }