Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added colors for highlighted state on buttons #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions Classes/UIButtons/DCBaseButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ public class DCBaseButton: UIButton {
updateColor()
}
}


@IBInspectable public var highlightedBackgroundColor: UIColor = UIColor(red: 37.0/255.0, green: 147.0/255.0, blue: 1.0/255.0, alpha: 1.0) {
didSet {
updateColor()
}
}

override public var enabled: Bool {
didSet {
updateColor()
Expand All @@ -64,7 +70,13 @@ public class DCBaseButton: UIButton {
updateColor()
}
}


override public var highlighted: Bool {
didSet {
updateColor()
}
}

// MARK: - Initializers

override public init(frame: CGRect) {
Expand Down Expand Up @@ -96,7 +108,15 @@ public class DCBaseButton: UIButton {
// MARK: - Misc

public func updateColor() {
backgroundColor = enabled ? (selected ? selectedBackgroundColor : normalBackgroundColor) : disabledBackgroundColor
if (enabled==false){
backgroundColor = disabledBackgroundColor
} else if (selected==true){
backgroundColor = selectedBackgroundColor
} else if (highlighted==true){
backgroundColor = highlightedBackgroundColor
} else {
backgroundColor = normalBackgroundColor
}
}

}
20 changes: 17 additions & 3 deletions Classes/UIButtons/DCBorderedButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ public class DCBorderedButton: DCBaseButton {
updateColor()
}
}


@IBInspectable public var highlightedBorderColor: UIColor = UIColor(red: 37.0/255.0, green: 147.0/255.0, blue: 1.0/255.0, alpha: 1.0) {
didSet {
updateColor()
}
}

@IBInspectable public var cornerRadius: CGFloat {
get {
return layer.cornerRadius
Expand Down Expand Up @@ -87,7 +93,15 @@ public class DCBorderedButton: DCBaseButton {

override public func updateColor() {
super.updateColor()
layer.borderColor = enabled ? (selected ? selectedBorderColor.CGColor : normalBorderColor.CGColor) : disabledBorderColor.CGColor
if (enabled==false){
layer.borderColor = disabledBorderColor.CGColor
} else if (selected==true){
layer.borderColor = selectedBorderColor.CGColor
} else if (highlighted==true){
layer.borderColor = highlightedBorderColor.CGColor
} else {
layer.borderColor = normalBorderColor.CGColor
}
}
}