|
@@ -59,7 +59,7 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
|
|
|
ComponentLibrary.shared.configButtonComponent(properties: _properties)
|
|
|
|
|
|
- self.reloadData()
|
|
|
+ reloadData()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -67,23 +67,27 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
//MARK: - setupUI
|
|
|
|
|
|
func setupUI() {
|
|
|
- self.leftIcon.isHidden = true
|
|
|
- self.label.isHidden = true
|
|
|
- self.rightIcon.isHidden = true
|
|
|
+ leftIcon.isHidden = true
|
|
|
+ label.isHidden = true
|
|
|
+ rightIcon.isHidden = true
|
|
|
|
|
|
- if self.properties.onlyIcon == true {
|
|
|
- self.leftIcon.isHidden = false
|
|
|
+ if properties.onlyIcon == true {
|
|
|
+ leftIcon.isHidden = false
|
|
|
} else {
|
|
|
- self.label.isHidden = false
|
|
|
- if self.properties.showLeftIcon == true && self.properties.showRightIcon == true {
|
|
|
- self.leftIcon.isHidden = false
|
|
|
- self.rightIcon.isHidden = false
|
|
|
+ label.isHidden = false
|
|
|
+ if properties.showLeftIcon == true &&
|
|
|
+ properties.showRightIcon == true {
|
|
|
|
|
|
- } else if self.properties.showLeftIcon == true && self.properties.showRightIcon == false {
|
|
|
- self.leftIcon.isHidden = false
|
|
|
+ leftIcon.isHidden = false
|
|
|
+ rightIcon.isHidden = false
|
|
|
|
|
|
- } else if self.properties.showLeftIcon == false && self.properties.showRightIcon == true {
|
|
|
- self.rightIcon.isHidden = false
|
|
|
+ } else if properties.showLeftIcon == true &&
|
|
|
+ properties.showRightIcon == false {
|
|
|
+ leftIcon.isHidden = false
|
|
|
+
|
|
|
+ } else if properties.showLeftIcon == false &&
|
|
|
+ properties.showRightIcon == true {
|
|
|
+ rightIcon.isHidden = false
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -92,44 +96,44 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
}
|
|
|
|
|
|
func refreshUI() {
|
|
|
- var fillColor = self.properties.propertyInfo.color_nor
|
|
|
- var borderWidth = self.properties.propertyInfo.borderWidth
|
|
|
- var borderColor = self.properties.propertyInfo.borderColor_nor
|
|
|
+ var fillColor = properties.propertyInfo.color_nor
|
|
|
+ var borderWidth = properties.propertyInfo.borderWidth
|
|
|
+ var borderColor = properties.propertyInfo.borderColor_nor
|
|
|
|
|
|
- var textColor = self.properties.propertyInfo.textColor
|
|
|
+ var textColor = properties.propertyInfo.textColor
|
|
|
|
|
|
- var leftImage = self.properties.propertyInfo.leftIcon_nor
|
|
|
- var rightImage = self.properties.propertyInfo.rightIcon_nor
|
|
|
+ var leftImage = properties.propertyInfo.leftIcon_nor
|
|
|
+ var rightImage = properties.propertyInfo.rightIcon_nor
|
|
|
|
|
|
- if self.properties.state == .normal {
|
|
|
+ if properties.state == .normal {
|
|
|
|
|
|
- } else if self.properties.state == .hover {
|
|
|
- fillColor = self.properties.propertyInfo.color_hov
|
|
|
- borderWidth = self.properties.propertyInfo.borderWidth
|
|
|
- borderColor = self.properties.propertyInfo.borderColor_hov
|
|
|
- textColor = self.properties.propertyInfo.textColor_hov
|
|
|
- leftImage = self.properties.propertyInfo.leftIcon_hov ?? self.properties.propertyInfo.leftIcon_nor
|
|
|
- rightImage = self.properties.propertyInfo.rightIcon_hov ?? self.properties.propertyInfo.rightIcon_nor
|
|
|
- } else if self.properties.state == .pressed {
|
|
|
- fillColor = self.properties.propertyInfo.color_active
|
|
|
- borderWidth = self.properties.propertyInfo.borderWidth
|
|
|
- borderColor = self.properties.propertyInfo.borderColor_active
|
|
|
- textColor = self.properties.propertyInfo.textColor_Active
|
|
|
- leftImage = self.properties.propertyInfo.leftIcon_press ?? self.properties.propertyInfo.leftIcon_nor
|
|
|
- rightImage = self.properties.propertyInfo.rightIcon_press ?? self.properties.propertyInfo.rightIcon_nor
|
|
|
+ } else if properties.state == .hover {
|
|
|
+ fillColor = properties.propertyInfo.color_hov
|
|
|
+ borderWidth = properties.propertyInfo.borderWidth
|
|
|
+ borderColor = properties.propertyInfo.borderColor_hov
|
|
|
+ textColor = properties.propertyInfo.textColor_hov
|
|
|
+ leftImage = properties.propertyInfo.leftIcon_hov ?? properties.propertyInfo.leftIcon_nor
|
|
|
+ rightImage = properties.propertyInfo.rightIcon_hov ?? properties.propertyInfo.rightIcon_nor
|
|
|
+ } else if properties.state == .pressed {
|
|
|
+ fillColor = properties.propertyInfo.color_active
|
|
|
+ borderWidth = properties.propertyInfo.borderWidth
|
|
|
+ borderColor = properties.propertyInfo.borderColor_active
|
|
|
+ textColor = properties.propertyInfo.textColor_Active
|
|
|
+ leftImage = properties.propertyInfo.leftIcon_press ?? properties.propertyInfo.leftIcon_nor
|
|
|
+ rightImage = properties.propertyInfo.rightIcon_press ?? properties.propertyInfo.rightIcon_nor
|
|
|
}
|
|
|
- if self.properties.isDisabled == true {
|
|
|
- fillColor = self.properties.propertyInfo.color_dis
|
|
|
- borderWidth = self.properties.propertyInfo.borderWidth
|
|
|
- borderColor = self.properties.propertyInfo.borderColor_dis
|
|
|
- textColor = self.properties.propertyInfo.textColor_dis
|
|
|
- leftImage = self.properties.propertyInfo.leftIcon_dis ?? self.properties.propertyInfo.leftIcon_nor
|
|
|
- rightImage = self.properties.propertyInfo.rightIcon_dis ?? self.properties.propertyInfo.rightIcon_nor
|
|
|
+ if properties.isDisabled == true {
|
|
|
+ fillColor = properties.propertyInfo.color_dis
|
|
|
+ borderWidth = properties.propertyInfo.borderWidth
|
|
|
+ borderColor = properties.propertyInfo.borderColor_dis
|
|
|
+ textColor = properties.propertyInfo.textColor_dis
|
|
|
+ leftImage = properties.propertyInfo.leftIcon_dis ?? properties.propertyInfo.leftIcon_nor
|
|
|
+ rightImage = properties.propertyInfo.rightIcon_dis ?? properties.propertyInfo.rightIcon_nor
|
|
|
}
|
|
|
|
|
|
contendBox.fillColor = fillColor
|
|
|
contendBox.borderColor = borderColor
|
|
|
- contendBox.cornerRadius = self.properties.propertyInfo.cornerRadius
|
|
|
+ contendBox.cornerRadius = properties.propertyInfo.cornerRadius
|
|
|
contendBox.borderWidth = borderWidth
|
|
|
|
|
|
label.textColor = textColor
|
|
@@ -137,14 +141,14 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
label.font = properties.propertyInfo.textFont
|
|
|
|
|
|
if let image = leftImage {
|
|
|
- self.leftIcon.image = image
|
|
|
+ leftIcon.image = image
|
|
|
}
|
|
|
|
|
|
if let image = rightImage {
|
|
|
- self.rightIcon.image = image
|
|
|
+ rightIcon.image = image
|
|
|
}
|
|
|
|
|
|
- self.label.stringValue = self.properties.buttonText ?? ""
|
|
|
+ label.stringValue = properties.buttonText ?? ""
|
|
|
|
|
|
// let paragraphStyle = NSMutableParagraphStyle()
|
|
|
// paragraphStyle.maximumLineHeight = 24
|
|
@@ -163,44 +167,44 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
// ])
|
|
|
// label.attributedStringValue = attributedString
|
|
|
|
|
|
- self.leftImgWidthConst.constant = self.properties.propertyInfo.imageWidth
|
|
|
- self.rightImgWidthConst.constant = self.leftImgWidthConst.constant
|
|
|
+ leftImgWidthConst.constant = properties.propertyInfo.imageWidth
|
|
|
+ rightImgWidthConst.constant = leftImgWidthConst.constant
|
|
|
|
|
|
- if self.properties.onlyIcon == true {
|
|
|
- self.properties.propertyInfo.viewWidth = self.properties.propertyInfo.viewHeight
|
|
|
- let viewWidth = self.properties.propertyInfo.viewWidth
|
|
|
- self.leftImgLeftConst.constant = (viewWidth - self.leftImgWidthConst.constant)/2
|
|
|
+ if properties.onlyIcon == true {
|
|
|
+ properties.propertyInfo.viewWidth = properties.propertyInfo.viewHeight
|
|
|
+ let viewWidth = properties.propertyInfo.viewWidth
|
|
|
+ leftImgLeftConst.constant = (viewWidth - leftImgWidthConst.constant)/2
|
|
|
|
|
|
} else {
|
|
|
- let viewWidth = self.frame.size.width
|
|
|
- let imageWidth = self.properties.propertyInfo.imageWidth
|
|
|
- let layoutGap = self.properties.propertyInfo.layout_gap
|
|
|
-
|
|
|
- self.label.sizeToFit()
|
|
|
- var labelRect = self.label.frame
|
|
|
- labelRect.origin.y = (CGRectGetHeight(self.frame) - labelRect.size.height)/2
|
|
|
+ let viewWidth = frame.size.width
|
|
|
+ let imageWidth = properties.propertyInfo.imageWidth
|
|
|
+ let layoutGap = properties.propertyInfo.layout_gap
|
|
|
+
|
|
|
+ label.sizeToFit()
|
|
|
+ var labelRect = label.frame
|
|
|
+ labelRect.origin.y = (CGRectGetHeight(frame) - labelRect.size.height)/2
|
|
|
|
|
|
- if self.properties.showLeftIcon == true && self.properties.showRightIcon == true {
|
|
|
- self.leftIcon.isHidden = false
|
|
|
- self.rightIcon.isHidden = false
|
|
|
+ if properties.showLeftIcon == true && properties.showRightIcon == true {
|
|
|
+ leftIcon.isHidden = false
|
|
|
+ rightIcon.isHidden = false
|
|
|
|
|
|
labelRect.origin.x = (viewWidth - labelRect.size.width - imageWidth*2 - layoutGap*2)/2.0 + imageWidth + layoutGap
|
|
|
- } else if self.properties.showLeftIcon == true && self.properties.showRightIcon == false {
|
|
|
- self.leftIcon.isHidden = false
|
|
|
+ } else if properties.showLeftIcon == true && properties.showRightIcon == false {
|
|
|
+ leftIcon.isHidden = false
|
|
|
|
|
|
labelRect.origin.x = (viewWidth - labelRect.size.width - imageWidth - layoutGap)/2.0 + imageWidth + layoutGap
|
|
|
- } else if self.properties.showLeftIcon == false && self.properties.showRightIcon == true {
|
|
|
- self.rightIcon.isHidden = false
|
|
|
+ } else if properties.showLeftIcon == false && properties.showRightIcon == true {
|
|
|
+ rightIcon.isHidden = false
|
|
|
|
|
|
labelRect.origin.x = (viewWidth - labelRect.size.width - imageWidth - layoutGap)/2.0
|
|
|
} else {
|
|
|
labelRect.origin.x = (viewWidth - labelRect.size.width)/2.0
|
|
|
}
|
|
|
- self.label.frame = labelRect
|
|
|
- self.leftImgLeftConst.constant = CGRectGetMinX(labelRect) - self.leftImgWidthConst.constant - layoutGap
|
|
|
- self.rightImgRightConst.constant = self.frame.size.width - CGRectGetMaxX(labelRect) - self.leftImgWidthConst.constant - layoutGap
|
|
|
+ label.frame = labelRect
|
|
|
+ leftImgLeftConst.constant = CGRectGetMinX(labelRect) - leftImgWidthConst.constant - layoutGap
|
|
|
+ rightImgRightConst.constant = frame.size.width - CGRectGetMaxX(labelRect) - leftImgWidthConst.constant - layoutGap
|
|
|
}
|
|
|
- self.leftIcon.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
|
|
|
+ leftIcon.autoresizingMask = [.minXMargin, .maxXMargin, .minYMargin, .maxYMargin]
|
|
|
|
|
|
}
|
|
|
|
|
@@ -241,10 +245,10 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
public override func mouseEntered(with event: NSEvent) {
|
|
|
super.mouseEntered(with: event)
|
|
|
|
|
|
- if self.properties.isDisabled == false && properties.state != .pressed {
|
|
|
- self.properties.state = .hover
|
|
|
+ if properties.isDisabled == false && properties.state != .pressed {
|
|
|
+ properties.state = .hover
|
|
|
}
|
|
|
- self.refreshUI()
|
|
|
+ refreshUI()
|
|
|
}
|
|
|
|
|
|
public override func mouseMoved(with event: NSEvent) {
|
|
@@ -256,38 +260,38 @@ public class ComponentButton: ComponentBaseXibView {
|
|
|
public override func mouseExited(with event: NSEvent) {
|
|
|
super.mouseExited(with: event)
|
|
|
|
|
|
- if self.properties.isDisabled == false && properties.state != .pressed {
|
|
|
- self.properties.state = .normal
|
|
|
+ if properties.isDisabled == false && properties.state != .pressed {
|
|
|
+ properties.state = .normal
|
|
|
}
|
|
|
|
|
|
- self.refreshUI()
|
|
|
+ refreshUI()
|
|
|
}
|
|
|
|
|
|
public override func mouseDown(with event: NSEvent) {
|
|
|
super.mouseDown(with: event)
|
|
|
|
|
|
mouseDownEnable = false
|
|
|
- if self.properties.isDisabled == false && properties.state != .pressed {
|
|
|
- self.properties.state = .pressed
|
|
|
+ if properties.isDisabled == false && properties.state != .pressed {
|
|
|
+ properties.state = .pressed
|
|
|
|
|
|
mouseDownEnable = true
|
|
|
}
|
|
|
|
|
|
- self.refreshUI()
|
|
|
+ refreshUI()
|
|
|
|
|
|
}
|
|
|
|
|
|
public override func mouseUp(with event: NSEvent) {
|
|
|
super.mouseUp(with: event)
|
|
|
|
|
|
- if self.properties.isDisabled == false &&
|
|
|
+ if properties.isDisabled == false &&
|
|
|
properties.keepActiveState == false &&
|
|
|
mouseDownEnable == true {
|
|
|
- self.properties.state = .normal
|
|
|
+ properties.state = .normal
|
|
|
}
|
|
|
- self.refreshUI()
|
|
|
+ refreshUI()
|
|
|
|
|
|
- if self.properties.isDisabled == false &&
|
|
|
+ if properties.isDisabled == false &&
|
|
|
mouseDownEnable == true {
|
|
|
if let target = target, let action = action {
|
|
|
_ = target.perform(action, with: self)
|