|
@@ -14,7 +14,7 @@ import Cocoa
|
|
|
case PopUpButton
|
|
|
}
|
|
|
|
|
|
-class KMDesignButton: NSViewController {
|
|
|
+class KMDesignButton: KMDesignBase {
|
|
|
|
|
|
@IBOutlet weak var mainBox: NSBox!
|
|
|
@IBOutlet weak var button : NSButton!
|
|
@@ -72,48 +72,7 @@ class KMDesignButton: NSViewController {
|
|
|
var textImage_paddingSpacing: Float = 16.0
|
|
|
var textImage_itemSpacing: Float = 8.0
|
|
|
|
|
|
- var textColor: NSColor = .black // 内容颜色
|
|
|
- var textColor_hov: NSColor = .black // 内容颜色
|
|
|
- var textColor_act: NSColor = .black // 内容颜色
|
|
|
- var textColor_disabled: NSColor = .black // 内容颜色
|
|
|
- var background: NSColor = .clear// 背景颜色
|
|
|
- var background_hov: NSColor = .clear// 背景颜色
|
|
|
- var background_act: NSColor = .clear// 背景颜色
|
|
|
- var background_disabled: NSColor = .clear// 背景颜色
|
|
|
- var borderWidth: Float = 1.0// 边框宽度
|
|
|
- var borderWidth_hov: Float = 1.0// 边框宽度
|
|
|
- var borderWidth_act: Float = 1.0// 边框宽度
|
|
|
- var borderWidth_disabled: Float = 1.0// 边框宽度
|
|
|
- var borderColor: NSColor = .clear// 边框颜色
|
|
|
- var borderColor_hov: NSColor = .clear// 边框颜色
|
|
|
- var borderColor_act: NSColor = .clear// 边框颜色
|
|
|
- var borderColor_disabled: NSColor = .clear// 边框颜色
|
|
|
- var cornerRadius: Float = 0.0// 边框圆角
|
|
|
- var cornerRadius_hov: Float = 0.0// 边框圆角
|
|
|
- var cornerRadius_act: Float = 0.0// 边框圆角
|
|
|
- var cornerRadius_disabled: Float = 0.0// 边框圆角
|
|
|
- var lineHeight: CGFloat = 20.0 // 默认 内容行高
|
|
|
- var lineHeight_hov: CGFloat = 20.0 // 默认 内容行高
|
|
|
- var lineHeight_act: CGFloat = 20.0 // 默认 内容行高
|
|
|
- var lineHeight_disabled: CGFloat = 20.0 // 默认 内容行高
|
|
|
- var font: NSFont = NSFont.systemFont(ofSize: 14.0) // 内容字体
|
|
|
- var font_hov: NSFont = NSFont.systemFont(ofSize: 14.0) // 内容字体
|
|
|
- var font_act: NSFont = NSFont.systemFont(ofSize: 14.0) // 内容字体
|
|
|
- var font_disabled: NSFont = NSFont.systemFont(ofSize: 14.0) // 内容字体
|
|
|
-
|
|
|
- var stringValue: String = ""// 内容
|
|
|
- var toolTip: String = "" // 提示文字
|
|
|
-
|
|
|
// button 通用属性
|
|
|
- var action: Selector? // 点击事件
|
|
|
- var target: AnyObject? // 对象目标
|
|
|
- var enabled: Bool = true // 是否可点击
|
|
|
- var state: KMDesignTokenState = .Norm
|
|
|
- var canHover: Bool = true // 是否可悬浮
|
|
|
- var isHidden: Bool = false // 是否隐藏
|
|
|
- var editable: Bool = false //是否允许编辑
|
|
|
-
|
|
|
- var buttonType: DesignButtonType = .Text
|
|
|
var textImage_type: KMTextImageButtonType = .Left
|
|
|
var textImage_state: KMDesignTokenState = .Norm
|
|
|
|
|
@@ -183,6 +142,60 @@ class KMDesignButton: NSViewController {
|
|
|
}
|
|
|
|
|
|
// MARK: Get、Set
|
|
|
+
|
|
|
+ var action: Selector {
|
|
|
+ get {
|
|
|
+ return _action!
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ _action = newValue
|
|
|
+ if _action != nil {
|
|
|
+ button.action = _action
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var target: AnyObject {
|
|
|
+ get {
|
|
|
+ return _target!
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ _target = newValue
|
|
|
+ if _target != nil {
|
|
|
+ button.target = _target
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var state: KMDesignTokenState {
|
|
|
+ get {
|
|
|
+ return _state
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ _state = newValue
|
|
|
+ updateUI()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var enabled: Bool {
|
|
|
+ get {
|
|
|
+ return _enabled
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ _enabled = newValue
|
|
|
+ self.view.isHidden = _enabled
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var isHidden: Bool {
|
|
|
+ get {
|
|
|
+ return _isHidden
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ _isHidden = newValue
|
|
|
+ button.isEnabled = _enabled
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
var image: NSImage {
|
|
|
get {
|
|
@@ -207,6 +220,18 @@ class KMDesignButton: NSViewController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ var toolTip: String {
|
|
|
+ get {
|
|
|
+ return _toolTip
|
|
|
+ }
|
|
|
+ set {
|
|
|
+ _toolTip = newValue
|
|
|
+ if _toolTip != "" {
|
|
|
+ button.toolTip = _toolTip
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// MARK: Private Methods
|
|
|
|
|
|
func updateUI() -> Void {
|
|
@@ -245,16 +270,7 @@ class KMDesignButton: NSViewController {
|
|
|
textButtonlabel.font = font_disabled
|
|
|
paragraphStyle.lineSpacing = lineHeight_disabled
|
|
|
}
|
|
|
- if action != nil {
|
|
|
- button.action = action
|
|
|
- button.target = target
|
|
|
- }
|
|
|
- button.isEnabled = enabled
|
|
|
textButtonlabel.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
|
|
|
- if toolTip != "" {
|
|
|
- button.toolTip = toolTip
|
|
|
- }
|
|
|
- self.view.isHidden = isHidden
|
|
|
} else if (buttonType == .Image) {
|
|
|
if (state == .Norm) {
|
|
|
imageButtonBox.fillColor = background
|
|
@@ -277,37 +293,25 @@ class KMDesignButton: NSViewController {
|
|
|
imageButtonBox.borderColor = borderColor_disabled
|
|
|
imageButtonBox.cornerRadius = CGFloat(cornerRadius_disabled)
|
|
|
}
|
|
|
- button.action = action
|
|
|
- button.target = target
|
|
|
- button.isEnabled = enabled
|
|
|
- if toolTip != "" {
|
|
|
- button.toolTip = toolTip
|
|
|
- }
|
|
|
- self.view.isHidden = isHidden
|
|
|
} else if (buttonType == .TextImage) {
|
|
|
let paragraphStyle = NSMutableParagraphStyle()
|
|
|
if textImage_type == .Up {
|
|
|
textImageButtonBox.contentView = textImage_upView
|
|
|
textImage_upTextfield.isEditable = editable
|
|
|
- textImage_upTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
|
|
|
textImage_upTextfield.font = font
|
|
|
} else if textImage_type == .Left {
|
|
|
textImageButtonBox.contentView = textImage_leftView
|
|
|
textImage_leftTextfield.isEditable = editable
|
|
|
- textImage_leftTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
|
|
|
textImage_leftTextfield.font = font
|
|
|
} else if textImage_type == .Down {
|
|
|
textImageButtonBox.contentView = textImage_downView
|
|
|
textImage_downTextfield.isEditable = editable
|
|
|
- textImage_downTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
|
|
|
textImage_downTextfield.font = font
|
|
|
} else if textImage_type == .Right {
|
|
|
textImageButtonBox.contentView = textImage_rightView
|
|
|
textImage_rightTextfield.isEditable = editable
|
|
|
- textImage_rightTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
|
|
|
textImage_rightTextfield.font = font
|
|
|
}
|
|
|
- button.isEnabled = enabled
|
|
|
|
|
|
if textImage_state == .Norm {
|
|
|
textImageButtonBox.fillColor = background
|
|
@@ -386,13 +390,6 @@ class KMDesignButton: NSViewController {
|
|
|
textImageButtonBox.cornerRadius = CGFloat(cornerRadius_disabled)
|
|
|
paragraphStyle.lineSpacing = lineHeight_disabled
|
|
|
}
|
|
|
- button.target = target
|
|
|
- button.action = action
|
|
|
- button.isEnabled = enabled
|
|
|
- if toolTip != "" {
|
|
|
- button.toolTip = toolTip
|
|
|
- }
|
|
|
- self.view.isHidden = isHidden
|
|
|
|
|
|
textImage_upImageHeight.constant = CGFloat(textImage_imageHeight)
|
|
|
textImage_upImageWidth.constant = CGFloat(textImage_imageWidth)
|
|
@@ -404,15 +401,19 @@ class KMDesignButton: NSViewController {
|
|
|
textImage_rightImageWidth.constant = CGFloat(textImage_imageWidth)
|
|
|
|
|
|
if textImage_type == .Up {
|
|
|
+ textImage_upTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
|
|
|
textImage_upPadding_spacing.constant = CGFloat(textImage_paddingSpacing)
|
|
|
textImage_upItem_spacing.constant = CGFloat(textImage_itemSpacing)
|
|
|
} else if textImage_type == .Left {
|
|
|
+ textImage_leftTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
|
|
|
textImage_leftPadding_spacing.constant = CGFloat(textImage_paddingSpacing)
|
|
|
textImage_leftItem_spacing.constant = CGFloat(textImage_itemSpacing)
|
|
|
} else if textImage_type == .Down {
|
|
|
+ textImage_downTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
|
|
|
textImage_downPadding_spacing.constant = CGFloat(textImage_paddingSpacing)
|
|
|
textImage_downItem_spacing.constant = CGFloat(textImage_itemSpacing)
|
|
|
} else if textImage_type == .Right {
|
|
|
+ textImage_rightTextfield.attributedStringValue = NSAttributedString(string: stringValue, attributes: [NSAttributedString.Key.paragraphStyle: paragraphStyle])
|
|
|
textImage_rightPadding_spacing.constant = CGFloat(textImage_paddingSpacing)
|
|
|
textImage_rightItem_spacing.constant = CGFloat(textImage_itemSpacing)
|
|
|
}
|