KMDesignButton.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. //
  2. // KMDesignButton.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2023/2/18.
  6. //
  7. import Cocoa
  8. @objc enum DesignButtonType : Int {
  9. case Text = 0 // 纯文本按钮
  10. case Image // 纯图片按钮
  11. case TextImage // 文本+图片按钮,区分图片在上左下右位置
  12. case PopUpButton // PopUp按钮
  13. case RadioButton // 单选按钮
  14. case CheckBox // 多选按钮
  15. }
  16. @objcMembers class KMDesignButton: KMDesignBase {
  17. @IBOutlet weak var mainBox: NSBox!
  18. @IBOutlet weak var button : NSButton!
  19. // Text
  20. @IBOutlet weak var textButtonBox: KMMoveBox!
  21. @IBOutlet weak var textButtonlabel : NSTextField!
  22. // Image
  23. @IBOutlet weak var imageButtonBox: KMMoveBox!
  24. @IBOutlet weak var imageView1: NSImageView!
  25. // TextImage
  26. @IBOutlet weak var textImageButtonBox: KMMoveBox!
  27. @IBOutlet weak var textImage_upView: NSView!
  28. @IBOutlet weak var textImage_leftView: NSView!
  29. @IBOutlet weak var textImage_downView: NSView!
  30. @IBOutlet weak var textImage_rightView: NSView!
  31. @IBOutlet weak var textImage_upImageView: NSImageView!
  32. @IBOutlet weak var textImage_leftImageView: NSImageView!
  33. @IBOutlet weak var textImage_downImageView: NSImageView!
  34. @IBOutlet weak var textImage_rightImageView: NSImageView!
  35. @IBOutlet weak var textImage_upTextfield: NSTextField!
  36. @IBOutlet weak var textImage_leftTextfield: NSTextField!
  37. @IBOutlet weak var textImage_downTextfield: NSTextField!
  38. @IBOutlet weak var textImage_rightTextfield: NSTextField!
  39. @IBOutlet weak var textImage_upPadding_spacing: NSLayoutConstraint!
  40. @IBOutlet weak var textImage_upImageHeight: NSLayoutConstraint!
  41. @IBOutlet weak var textImage_upImageWidth: NSLayoutConstraint!
  42. @IBOutlet weak var textImage_upItem_spacing: NSLayoutConstraint!
  43. @IBOutlet weak var textImage_leftPadding_spacing: NSLayoutConstraint!
  44. @IBOutlet weak var textImage_leftImageHeight: NSLayoutConstraint!
  45. @IBOutlet weak var textImage_leftImageWidth: NSLayoutConstraint!
  46. @IBOutlet weak var textImage_leftItem_spacing: NSLayoutConstraint!
  47. @IBOutlet weak var textImage_downPadding_spacing: NSLayoutConstraint!
  48. @IBOutlet weak var textImage_downImageHeight: NSLayoutConstraint!
  49. @IBOutlet weak var textImage_downImageWidth: NSLayoutConstraint!
  50. @IBOutlet weak var textImage_downItem_spacing: NSLayoutConstraint!
  51. @IBOutlet weak var textImage_rightPadding_spacing: NSLayoutConstraint!
  52. @IBOutlet weak var textImage_rightImageHeight: NSLayoutConstraint!
  53. @IBOutlet weak var textImage_rightImageWidth: NSLayoutConstraint!
  54. @IBOutlet weak var textImage_rightItem_spacing: NSLayoutConstraint!
  55. @IBOutlet weak var radioButton_mainBox: KMMoveBox!
  56. @IBOutlet weak var radioButton_imageView: NSImageView!
  57. @IBOutlet weak var radioButton_label: NSTextField!
  58. @IBOutlet weak var radio_label_spacing: NSLayoutConstraint!
  59. @IBOutlet weak var radio_imageViewWidth: NSLayoutConstraint!
  60. @IBOutlet weak var radio_imageViewHeight: NSLayoutConstraint!
  61. @IBOutlet weak var mainBoxHeight : NSLayoutConstraint! // mainBox 高度约束
  62. @IBOutlet weak var mainBoxWidth : NSLayoutConstraint! // mainBox 宽度约束
  63. var height: Float = 32.0 // 高度
  64. var width: Float = 80.0 // 宽度
  65. var textImage_imageWidth: Float = 20.0// 图片宽度
  66. var textImage_imageHeight: Float = 20.0// 图片高度
  67. var textImage_paddingSpacing: Float = 16.0
  68. var textImage_itemSpacing: Float = 8.0
  69. // var image: NSImage = NSImage(named: "KMRadioButtonUnSelect")! // imageView 图片
  70. var radio_imageWidth = 16.0 // 图片宽度
  71. var radio_imageHeight = 16.0 // 图片高度
  72. var radio_label = 8.0 // imageView、label 水平间距
  73. // button 通用属性
  74. var textImage_type: KMTextImageButtonType = .Left
  75. var textImage_state: KMDesignTokenState = .Norm
  76. init(withType type: DesignButtonType) {
  77. super.init(nibName: "KMDesignButton", bundle: nil)
  78. self.buttonType = type
  79. }
  80. required init?(coder: NSCoder) {
  81. fatalError("init(coder:) has not been implemented")
  82. }
  83. override func viewDidLoad() {
  84. super.viewDidLoad()
  85. // Do view setup here.
  86. if (buttonType == .Text) {
  87. mainBox.contentView = textButtonBox
  88. } else if (buttonType == .Image) {
  89. mainBox.contentView = imageButtonBox
  90. } else if (buttonType == .TextImage) {
  91. mainBox.contentView = textImageButtonBox
  92. } else if (buttonType == .PopUpButton) {
  93. mainBox.contentView = textImageButtonBox
  94. } else if (buttonType == .RadioButton) || (buttonType == .CheckBox) {
  95. mainBox.contentView = radioButton_mainBox
  96. }
  97. textButtonBox.move = { [weak self](mouseEntered: Bool) -> Void in
  98. if self != nil {
  99. if mouseEntered {
  100. if self!.state != .Sel && self!.canHover && (self!.state != .Disabled) && (self!.state != .Act) {
  101. self!.state = .Hov
  102. self!.updateUI()
  103. }
  104. } else {
  105. if self!.state != .Sel && self!.canHover && (self!.state != .Disabled) && (self!.state != .Act) {
  106. self!.state = .Norm
  107. self!.updateUI()
  108. }
  109. }
  110. }
  111. }
  112. imageButtonBox.move = { [weak self](mouseEntered: Bool) -> Void in
  113. if self != nil {
  114. if mouseEntered {
  115. if self!.state != .Sel && self!.canHover && (self!.state != .Disabled) && (self!.state != .Act) {
  116. self!.state = .Hov
  117. self!.updateUI()
  118. }
  119. } else {
  120. if self!.state != .Sel && self!.canHover && (self!.state != .Disabled) && (self!.state != .Act) {
  121. self!.state = .Norm
  122. self!.updateUI()
  123. }
  124. }
  125. }
  126. }
  127. textImageButtonBox.move = { [weak self](mouseEntered: Bool) -> Void in
  128. if self != nil {
  129. if mouseEntered {
  130. if self!.state != .Sel && self!.canHover && (self!.state != .Disabled) && (self!.state != .Act) {
  131. self!.state = .Hov
  132. self!.updateUI()
  133. }
  134. } else {
  135. if self!.state != .Sel && self!.canHover && (self!.state != .Disabled) && (self!.state != .Act) {
  136. self!.state = .Norm
  137. self!.updateUI()
  138. }
  139. }
  140. }
  141. }
  142. radioButton_mainBox.move = { [weak self](mouseEntered: Bool) -> Void in
  143. if self != nil {
  144. if mouseEntered {
  145. if self!.state != .Checked_dis && self!.canHover && (self!.state != .Disabled) && (self!.state != .Checked) {
  146. self!.state = .Hov
  147. self!.updateUI()
  148. }
  149. } else {
  150. if self!.state != .Checked_dis && self!.canHover && (self!.state != .Disabled) && (self!.state != .Checked) {
  151. self!.state = .Norm
  152. self!.updateUI()
  153. }
  154. }
  155. }
  156. }
  157. // self.radioButton_mainBox.canHover = true
  158. // self.radioButton_mainBox.canClick = true
  159. // radioButton_mainBox.downCallback = { [weak self](downEntered: Bool, mouseBox: KMBox) -> Void in
  160. // if self != nil {
  161. // if self!.enabled {
  162. // if downEntered {
  163. // self!.canHover = false
  164. // self!.state = .Checked
  165. // self!.updateUI()
  166. // }
  167. // }
  168. // }
  169. // }
  170. // radioButton_mainBox.moveCallback = { [weak self](mouseEntered: Bool, mouseBox: KMBox) -> Void in
  171. // if self != nil {
  172. // if mouseEntered {
  173. // if self!.state != .Checked_dis && self!.canHover && (self!.state != .Disabled) && (self!.state != .Checked) {
  174. // self!.state = .Hov
  175. // self!.updateUI()
  176. // }
  177. // } else {
  178. // if self!.state != .Checked_dis && self!.canHover && (self!.state != .Disabled) && (self!.state != .Checked) {
  179. // self!.state = .Norm
  180. // self!.updateUI()
  181. // }
  182. // }
  183. // }
  184. // }
  185. }
  186. // MARK: Get、Set
  187. var action: Selector {
  188. get {
  189. return _action!
  190. }
  191. set {
  192. _action = newValue
  193. if _action != nil {
  194. button.action = _action
  195. }
  196. }
  197. }
  198. var target: AnyObject {
  199. get {
  200. return _target!
  201. }
  202. set {
  203. _target = newValue
  204. if _target != nil {
  205. button.target = _target
  206. }
  207. }
  208. }
  209. var state: KMDesignTokenState {
  210. get {
  211. return _state
  212. }
  213. set {
  214. _state = newValue
  215. updateUI()
  216. }
  217. }
  218. var enabled: Bool {
  219. get {
  220. return _enabled
  221. }
  222. set {
  223. _enabled = newValue
  224. self.button.isEnabled = _enabled
  225. if _enabled {
  226. state = .Norm
  227. } else {
  228. state = .Disabled
  229. }
  230. updateUI()
  231. }
  232. }
  233. var isHidden: Bool {
  234. get {
  235. return _isHidden
  236. }
  237. set {
  238. _isHidden = newValue
  239. self.view.isHidden = _isHidden
  240. }
  241. }
  242. var image: NSImage {
  243. get {
  244. return _image
  245. }
  246. set {
  247. _image = newValue
  248. updateUI()
  249. }
  250. }
  251. var image_hov: NSImage {
  252. get {
  253. if _image_hov == nil {
  254. return _image
  255. }
  256. return _image_hov!
  257. }
  258. set {
  259. _image_hov = newValue
  260. updateUI()
  261. }
  262. }
  263. var image_act: NSImage {
  264. get {
  265. if _image_act == nil {
  266. return _image
  267. }
  268. return _image_act!
  269. }
  270. set {
  271. _image_act = newValue
  272. updateUI()
  273. }
  274. }
  275. var image_disabled: NSImage {
  276. get {
  277. if _image_disabled == nil {
  278. return _image
  279. }
  280. return _image_disabled!
  281. }
  282. set {
  283. _image_disabled = newValue
  284. updateUI()
  285. }
  286. }
  287. var image_sel: NSImage {
  288. get {
  289. if (_image_sel == nil) {
  290. _image_sel = image
  291. }
  292. return _image_sel!
  293. }
  294. set {
  295. _image_sel = newValue
  296. updateUI()
  297. }
  298. }
  299. var image_checked: NSImage {
  300. get {
  301. if (_image_checked == nil) {
  302. _image_checked = image
  303. }
  304. return _image_checked!
  305. }
  306. set {
  307. _image_checked = newValue
  308. updateUI()
  309. }
  310. }
  311. var image_checkeddis: NSImage {
  312. get {
  313. if (_image_checkeddis == nil) {
  314. _image_checkeddis = image
  315. }
  316. return _image_checkeddis!
  317. }
  318. set {
  319. _image_checkeddis = newValue
  320. updateUI()
  321. }
  322. }
  323. var toolTip: String {
  324. get {
  325. return _toolTip
  326. }
  327. set {
  328. _toolTip = newValue
  329. if _toolTip != "" {
  330. button.toolTip = _toolTip
  331. }
  332. }
  333. }
  334. // MARK: Private Methods
  335. func updateUI() -> Void {
  336. if (buttonType == .Text) {
  337. let paragraphStyle = NSMutableParagraphStyle()
  338. if (state == .Norm) {
  339. textButtonBox.fillColor = background
  340. textButtonBox.borderWidth = CGFloat(borderWidth)
  341. textButtonBox.cornerRadius = CGFloat(cornerRadius)
  342. textButtonBox.borderColor = borderColor
  343. textButtonlabel.textColor = textColor
  344. textButtonlabel.font = font
  345. paragraphStyle.lineSpacing = lineHeight
  346. } else if (state == .Hov) {
  347. textButtonBox.fillColor = background_hov
  348. textButtonBox.borderWidth = CGFloat(borderWidth_hov)
  349. textButtonBox.cornerRadius = CGFloat(cornerRadius_hov)
  350. textButtonBox.borderColor = borderColor_hov
  351. textButtonlabel.textColor = textColor_hov
  352. textButtonlabel.font = font_hov
  353. paragraphStyle.lineSpacing = lineHeight_hov
  354. } else if (state == .Act) {
  355. textButtonBox.fillColor = background_act
  356. textButtonBox.borderWidth = CGFloat(borderWidth_act)
  357. textButtonBox.cornerRadius = CGFloat(cornerRadius_act)
  358. textButtonBox.borderColor = borderColor_act
  359. textButtonlabel.textColor = textColor_act
  360. textButtonlabel.font = font_act
  361. paragraphStyle.lineSpacing = lineHeight_act
  362. } else if (state == .Disabled) {
  363. textButtonBox.fillColor = background_disabled
  364. textButtonBox.borderWidth = CGFloat(borderWidth_disabled)
  365. textButtonBox.cornerRadius = CGFloat(cornerRadius_disabled)
  366. textButtonBox.borderColor = borderColor_disabled
  367. textButtonlabel.textColor = textColor_disabled
  368. textButtonlabel.font = font_disabled
  369. paragraphStyle.lineSpacing = lineHeight_disabled
  370. }
  371. textButtonlabel.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  372. } else if (buttonType == .Image) {
  373. if (state == .Norm) {
  374. imageButtonBox.fillColor = background
  375. imageButtonBox.borderWidth = CGFloat(borderWidth)
  376. imageButtonBox.borderColor = borderColor
  377. imageButtonBox.cornerRadius = CGFloat(cornerRadius)
  378. imageView1.image = image
  379. } else if (state == .Hov) {
  380. imageButtonBox.fillColor = background_hov
  381. imageButtonBox.borderWidth = CGFloat(borderWidth_hov)
  382. imageButtonBox.borderColor = borderColor_hov
  383. imageButtonBox.cornerRadius = CGFloat(cornerRadius_hov)
  384. imageView1.image = image_hov
  385. } else if (state == .Act) {
  386. imageButtonBox.fillColor = background_act
  387. imageButtonBox.borderWidth = CGFloat(borderWidth_act)
  388. imageButtonBox.borderColor = borderColor_act
  389. imageButtonBox.cornerRadius = CGFloat(cornerRadius_act)
  390. imageView1.image = image_act
  391. } else if (state == .Disabled) {
  392. imageButtonBox.fillColor = background_disabled
  393. imageButtonBox.borderWidth = CGFloat(borderWidth_disabled)
  394. imageButtonBox.borderColor = borderColor_disabled
  395. imageButtonBox.cornerRadius = CGFloat(cornerRadius_disabled)
  396. imageView1.image = image_disabled
  397. }
  398. } else if (buttonType == .TextImage) {
  399. let paragraphStyle = NSMutableParagraphStyle()
  400. if textImage_type == .Up {
  401. textImageButtonBox.contentView = textImage_upView
  402. textImage_upTextfield.isEditable = editable
  403. textImage_upTextfield.font = font
  404. } else if textImage_type == .Left {
  405. textImageButtonBox.contentView = textImage_leftView
  406. textImage_leftTextfield.isEditable = editable
  407. textImage_leftTextfield.font = font
  408. } else if textImage_type == .Down {
  409. textImageButtonBox.contentView = textImage_downView
  410. textImage_downTextfield.isEditable = editable
  411. textImage_downTextfield.font = font
  412. } else if textImage_type == .Right {
  413. textImageButtonBox.contentView = textImage_rightView
  414. textImage_rightTextfield.isEditable = editable
  415. textImage_rightTextfield.font = font
  416. }
  417. if textImage_state == .Norm {
  418. textImageButtonBox.fillColor = background
  419. textImageButtonBox.borderColor = borderColor
  420. if textImage_type == .Up {
  421. textImage_upImageView.image = image
  422. textImage_upTextfield.textColor = textColor
  423. } else if textImage_type == .Left {
  424. textImage_leftImageView.image = image
  425. textImage_leftTextfield.textColor = textColor
  426. } else if textImage_type == .Down {
  427. textImage_downImageView.image = image
  428. textImage_downTextfield.textColor = textColor
  429. } else if textImage_type == .Right {
  430. textImage_rightImageView.image = image
  431. textImage_rightTextfield.textColor = textColor
  432. }
  433. textImageButtonBox.borderWidth = CGFloat(borderWidth)
  434. textImageButtonBox.cornerRadius = CGFloat(cornerRadius)
  435. paragraphStyle.lineSpacing = lineHeight
  436. } else if state == .Hov {
  437. textImageButtonBox.fillColor = background_hov
  438. textImageButtonBox.borderColor = borderColor_hov
  439. if textImage_type == .Up {
  440. textImage_upImageView.image = image_hov
  441. textImage_upTextfield.textColor = textColor_hov
  442. } else if textImage_type == .Left {
  443. textImage_leftImageView.image = image_hov
  444. textImage_leftTextfield.textColor = textColor_hov
  445. } else if textImage_type == .Down {
  446. textImage_downImageView.image = image_hov
  447. textImage_downTextfield.textColor = textColor_hov
  448. } else if textImage_type == .Right {
  449. textImage_rightImageView.image = image_hov
  450. textImage_rightTextfield.textColor = textColor_hov
  451. }
  452. textImageButtonBox.borderWidth = CGFloat(borderWidth_hov)
  453. textImageButtonBox.cornerRadius = CGFloat(cornerRadius_hov)
  454. paragraphStyle.lineSpacing = lineHeight_hov
  455. } else if state == .Act {
  456. textImageButtonBox.fillColor = background_act
  457. textImageButtonBox.borderColor = borderColor_act
  458. if textImage_type == .Up {
  459. textImage_upImageView.image = image_act
  460. textImage_upTextfield.textColor = textColor_act
  461. } else if textImage_type == .Left {
  462. textImage_leftImageView.image = image_act
  463. textImage_leftTextfield.textColor = textColor_act
  464. } else if textImage_type == .Down {
  465. textImage_downImageView.image = image_act
  466. textImage_downTextfield.textColor = textColor_act
  467. } else if textImage_type == .Right {
  468. textImage_rightImageView.image = image_act
  469. textImage_rightTextfield.textColor = textColor_act
  470. }
  471. textImageButtonBox.borderWidth = CGFloat(borderWidth_act)
  472. textImageButtonBox.cornerRadius = CGFloat(cornerRadius_act)
  473. paragraphStyle.lineSpacing = lineHeight_act
  474. } else if state == .Disabled {
  475. textImageButtonBox.fillColor = background_disabled
  476. textImageButtonBox.borderColor = borderColor_disabled
  477. if textImage_type == .Up {
  478. textImage_upImageView.image = image_disabled
  479. textImage_upTextfield.textColor = textColor_disabled
  480. } else if textImage_type == .Left {
  481. textImage_leftImageView.image = image_disabled
  482. textImage_leftTextfield.textColor = textColor_disabled
  483. } else if textImage_type == .Down {
  484. textImage_downImageView.image = image_disabled
  485. textImage_downTextfield.textColor = textColor_disabled
  486. } else if textImage_type == .Right {
  487. textImage_rightImageView.image = image_disabled
  488. textImage_rightTextfield.textColor = textColor_disabled
  489. }
  490. textImageButtonBox.borderWidth = CGFloat(borderWidth_disabled)
  491. textImageButtonBox.cornerRadius = CGFloat(cornerRadius_disabled)
  492. paragraphStyle.lineSpacing = lineHeight_disabled
  493. }
  494. textImage_upImageHeight.constant = CGFloat(textImage_imageHeight)
  495. textImage_upImageWidth.constant = CGFloat(textImage_imageWidth)
  496. textImage_leftImageHeight.constant = CGFloat(textImage_imageHeight)
  497. textImage_leftImageWidth.constant = CGFloat(textImage_imageWidth)
  498. textImage_downImageHeight.constant = CGFloat(textImage_imageHeight)
  499. textImage_downImageWidth.constant = CGFloat(textImage_imageWidth)
  500. textImage_rightImageHeight.constant = CGFloat(textImage_imageHeight)
  501. textImage_rightImageWidth.constant = CGFloat(textImage_imageWidth)
  502. if textImage_type == .Up {
  503. textImage_upTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  504. textImage_upPadding_spacing.constant = CGFloat(textImage_paddingSpacing)
  505. textImage_upItem_spacing.constant = CGFloat(textImage_itemSpacing)
  506. } else if textImage_type == .Left {
  507. textImage_leftTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  508. textImage_leftPadding_spacing.constant = CGFloat(textImage_paddingSpacing)
  509. textImage_leftItem_spacing.constant = CGFloat(textImage_itemSpacing)
  510. } else if textImage_type == .Down {
  511. textImage_downTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  512. textImage_downPadding_spacing.constant = CGFloat(textImage_paddingSpacing)
  513. textImage_downItem_spacing.constant = CGFloat(textImage_itemSpacing)
  514. } else if textImage_type == .Right {
  515. textImage_rightTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  516. textImage_rightPadding_spacing.constant = CGFloat(textImage_paddingSpacing)
  517. textImage_rightItem_spacing.constant = CGFloat(textImage_itemSpacing)
  518. }
  519. } else if (buttonType == .RadioButton) || (buttonType == .CheckBox) {
  520. let paragraphStyle = NSMutableParagraphStyle()
  521. if (state == .Norm) {
  522. if (buttonType == .RadioButton) {
  523. radioButton_imageView.image = NSImage(named: "KMRadioButtonUnSelect")
  524. } else {
  525. radioButton_imageView.image = NSImage(named: "icon_btn_checkbox_unsel")
  526. }
  527. radioButton_label.font = font
  528. radioButton_label.textColor = textColor
  529. paragraphStyle.lineSpacing = lineHeight
  530. } else if (state == .Hov) {
  531. if (buttonType == .RadioButton) {
  532. radioButton_imageView.image = NSImage(named: "KMRadioButtonHov")
  533. } else {
  534. radioButton_imageView.image = NSImage(named: "icon_btn_checkbox_hov")
  535. }
  536. radioButton_label.font = font_hov
  537. radioButton_label.textColor = textColor_hov
  538. paragraphStyle.lineSpacing = lineHeight_hov
  539. } else if (state == .Disabled) {
  540. if (buttonType == .RadioButton) {
  541. radioButton_imageView.image = NSImage(named: "KMRadioButtonUnSel_Disabled")
  542. } else {
  543. radioButton_imageView.image = NSImage(named: "icon_btn_checkbox_unsel_Disabled")
  544. }
  545. radioButton_label.font = font_disabled
  546. radioButton_label.textColor = textColor_disabled
  547. paragraphStyle.lineSpacing = lineHeight_disabled
  548. } else if (state == .Checked) {
  549. if (buttonType == .RadioButton) {
  550. radioButton_imageView.image = NSImage(named: "KMRadioButtonSelect")
  551. } else {
  552. radioButton_imageView.image = NSImage(named: "icon_btn_checkbox_sel")
  553. }
  554. radioButton_label.font = font_checked
  555. radioButton_label.textColor = textColor_checked
  556. paragraphStyle.lineSpacing = lineHeight_checked
  557. } else if (state == .Checked_dis) {
  558. if (buttonType == .RadioButton) {
  559. radioButton_imageView.image = NSImage(named: "KMRadioButtonSel_Disabled")
  560. } else {
  561. radioButton_imageView.image = NSImage(named: "icon_btn_checkbox_sel_Disabled")
  562. }
  563. radioButton_label.font = font_checkeddis
  564. radioButton_label.textColor = textColor_checkeddis
  565. paragraphStyle.lineSpacing = lineHeight_checkeddis
  566. }
  567. radioButton_label.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
  568. radio_label_spacing.constant = radio_label
  569. radio_imageViewWidth.constant = radio_imageWidth
  570. radio_imageViewHeight.constant = radio_imageHeight
  571. }
  572. }
  573. }