KMSecureEncryptSuccessTipView.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. //
  2. // KMSecureEncryptSuccessTipView.swift
  3. // PDF Master
  4. //
  5. // Created by tangchao on 2022/11/28.
  6. //
  7. import Cocoa
  8. typealias KMSecureEncryptSuccessTipViewItemClick = () ->()
  9. class KMSecureEncryptSuccessTipView: NSView {
  10. private var iconImageView = NSImageView()
  11. private var iconSelectImageView = NSImageView()
  12. private var despLabel = NSTextField(wrappingLabelWithString: "")
  13. private var titleLabel = NSTextField(labelWithString: "")
  14. private var closeButton = NSButton()
  15. private var knowButtonVC: KMDesignButton?
  16. var itemClick: KMSecureEncryptSuccessTipViewItemClick!
  17. private var knowButtonSize: NSSize = NSMakeSize(140, 32)
  18. override init(frame frameRect: NSRect) {
  19. super.init(frame: frameRect)
  20. self.initSubViews()
  21. }
  22. required init?(coder: NSCoder) {
  23. super.init(coder: coder)
  24. self.initSubViews()
  25. }
  26. override var isFlipped: Bool {
  27. return true
  28. }
  29. func initSubViews() {
  30. wantsLayer = true
  31. layer?.backgroundColor = NSColor.km_init(hex: "#E8F5FF").cgColor
  32. layer?.cornerRadius = 8
  33. self.shadow = NSShadow()
  34. self.layer?.shadowColor = NSColor.km_init(hex: "#00000029").cgColor
  35. self.layer?.shadowOpacity = 1
  36. self.layer?.shadowRadius = 8
  37. self.layer?.shadowOffset = CGSize(width: 0, height: -3)
  38. self.addSubview(self.titleLabel)
  39. self.addSubview(self.closeButton)
  40. addSubview(iconImageView)
  41. addSubview(despLabel)
  42. self.knowButtonVC = KMDesignButton(withType: .Text)
  43. self.addSubview(self.knowButtonVC!.view)
  44. self.iconImageView.addSubview(self.iconSelectImageView)
  45. self.titleLabel.stringValue = NSLocalizedString("Set password successfully", comment: "")
  46. self.titleLabel.font = NSFont.SFProTextRegularFont(14)
  47. self.titleLabel.textColor = NSColor.titleColor()
  48. self.closeButton.isBordered = false
  49. self.closeButton.image = NSImage(named: "KMImageNameWhiteClose")
  50. self.closeButton.target = self
  51. self.closeButton.action = #selector(knowButtonAction)
  52. iconImageView.wantsLayer = true
  53. iconImageView.image = NSImage(named: "KMImageNameTipSelectedBackgroud")
  54. self.iconSelectImageView.image = NSImage(named: "KMImageNameTipSelected")
  55. self.despLabel.isSelectable = false
  56. despLabel.stringValue = NSLocalizedString("The security settings won't take effect until the document is saved. You can change the security settings before closing the file.", comment: "")
  57. let ps = NSMutableParagraphStyle()
  58. ps.lineSpacing = 7
  59. despLabel.attributedStringValue = NSAttributedString(string: despLabel.stringValue, attributes: [.foregroundColor : NSColor.despColor(),
  60. .font : NSFont.SFProTextRegularFont(14),
  61. .paragraphStyle : ps
  62. ])
  63. self.knowButtonVC?.stringValue = NSLocalizedString("Got it", comment: "")
  64. self.knowButtonVC?.button(type: .Ghost, size: .m)
  65. self.knowButtonVC?.target = self
  66. self.knowButtonVC?.action = #selector(knowButtonAction)
  67. let size = self.knowButtonVC?.stringValue.boundingRect(with: NSMakeSize(1000, self.knowButtonSize.height), options: [.usesLineFragmentOrigin, .usesFontLeading], attributes: [.foregroundColor : NSColor.buttonTitleColor(), .font : NSFont.SFProTextRegularFont(14)]).size
  68. if (size == nil || size!.width < 40) {
  69. self.knowButtonSize.width = 70
  70. } else {
  71. self.knowButtonSize.width = size!.width + 34
  72. }
  73. }
  74. override func layout() {
  75. super.layout()
  76. let width: CGFloat = NSWidth(self.bounds)
  77. let height: CGFloat = NSHeight(self.bounds)
  78. let iconSize: CGFloat = 20
  79. iconImageView.frame = NSMakeRect(18, 18, iconSize, iconSize)
  80. self.iconSelectImageView.frame = self.iconImageView.bounds
  81. self.titleLabel.frame = NSMakeRect(self.iconImageView.frame.maxX+10, 16, 295, 22)
  82. self.closeButton.frame = NSMakeRect(width-34, 10, 24, 24)
  83. let despX: CGFloat = iconImageView.frame.maxX+12
  84. let despY: CGFloat = self.titleLabel.frame.maxY+8
  85. despLabel.frame = NSMakeRect(despX, despY, width-despX-8, height-despY-45)
  86. let knowSize = self.knowButtonSize
  87. self.knowButtonVC?.view.frame = NSMakeRect(width-knowSize.width-16, height-knowSize.height-16, knowSize.width, knowSize.height)
  88. }
  89. @objc func knowButtonAction() {
  90. guard let callback = itemClick else {
  91. return
  92. }
  93. callback()
  94. }
  95. }