HyperLinkButton.swift 784 B

1234567891011121314151617181920212223242526272829303132333435
  1. //
  2. // HyperLinkButton.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/1/10.
  6. //
  7. import Cocoa
  8. @objcMembers class HyperLinkButton: KMButton {
  9. override func draw(_ dirtyRect: NSRect) {
  10. super.draw(dirtyRect)
  11. // Drawing code here.
  12. }
  13. override class func awakeFromNib() {
  14. super.awakeFromNib()
  15. }
  16. override var title: String {
  17. didSet {
  18. self.attributedTitle = self.hyperlink()!
  19. }
  20. }
  21. func hyperlink() -> NSAttributedString? {
  22. var str = NSMutableAttributedString.init(attributedString: self.attributedTitle)
  23. str.addAttributes([NSAttributedString.Key.underlineStyle : true], range: NSRange(location: 0, length: self.title.count))
  24. return str;
  25. }
  26. }