12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- //
- // KMCloudNoNetworkView.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2023/2/14.
- //
- import Cocoa
- typealias KMCloudNoNetworkViewItemClick = (Int) -> ()
- class KMCloudNoNetworkView: NSView {
- var imageView = NSImageView()
- var titleLabel = NSTextField(labelWithString: "")
- var despLabel = NSTextField(labelWithString: "")
- var funcButton = NSButton()
-
- var itemClick: KMCloudNoNetworkViewItemClick?
-
- override var isFlipped: Bool {
- return true
- }
-
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
-
- initSubViews()
- }
-
- required init?(coder: NSCoder) {
- super.init(coder: coder)
-
- initSubViews()
- }
-
- public func initSubViews() {
- self.addSubview(self.imageView)
- self.addSubview(self.titleLabel)
- self.addSubview(self.despLabel)
- self.addSubview(self.funcButton)
-
- self.titleLabel.alignment = .center
- self.titleLabel.stringValue = NSLocalizedString("No network detected", comment: "")
- self.despLabel.alignment = .center
- self.despLabel.stringValue = NSLocalizedString("To access your files, please connect to the Internet and try again.", comment: "")
- self.funcButton.isBordered = false
- self.funcButton.wantsLayer = true
- self.funcButton.title = NSLocalizedString("Retry", comment: "")
- self.funcButton.target = self
- self.funcButton.action = #selector(funcButtonAction)
- }
-
- override func layout() {
- super.layout()
- let width: CGFloat = NSWidth(self.bounds)
-
- let imageSize: NSSize = NSMakeSize(80, 80)
- self.imageView.frame = NSMakeRect((width-imageSize.width)*0.5, 20, imageSize.width, imageSize.height)
-
- self.titleLabel.frame = NSMakeRect(0, self.imageView.frame.maxY+20, width, 22)
- self.despLabel.frame = NSMakeRect(0, self.titleLabel.frame.maxY+2, width, 20)
-
- let buttonSize: NSSize = NSMakeSize(68, 32)
- self.funcButton.frame = NSMakeRect((width-buttonSize.width)*0.5, self.despLabel.frame.maxY+8, buttonSize.width, buttonSize.height)
- }
-
- @objc func funcButtonAction() {
- guard let callback = self.itemClick else {
- return
- }
- callback(1)
- }
- }
|