Skip to content

Commit

Permalink
Update radioButton card to use dynamic colors
Browse files Browse the repository at this point in the history
  • Loading branch information
lkeude96 committed Oct 30, 2019
1 parent 9276990 commit a00ad4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions CardParts/src/Classes/Card Parts/CardPartRadioButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public class CardPartRadioButton: UIButton, CardPartView {
var outerCircleLayer = CAShapeLayer()
var innerCircleLayer = CAShapeLayer()

public var outerCircleColor:UIColor = .blue {
public var outerCircleColor:UIColor = .SystemBlue {
didSet{
outerCircleLayer.strokeColor = outerCircleColor.cgColor
outerCircleLayer.strokeColor = outerCircleColor.cgColor(with: traitCollection)
}
}

public var innerCircleColor:UIColor = .blue {
public var innerCircleColor:UIColor = .SystemBlue {
didSet {
setFillState()
}
Expand Down Expand Up @@ -85,10 +85,15 @@ public class CardPartRadioButton: UIButton, CardPartView {
super.layoutSubviews()
setCircleLayouts()
}

public override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
outerCircleLayer.strokeColor = outerCircleColor.cgColor(with: traitCollection)
setFillState()
}

/// fills the color inside the button based the selected state.
private func setFillState() {
innerCircleLayer.fillColor = self.isSelected ? outerCircleColor.cgColor : UIColor.clear.cgColor
innerCircleLayer.fillColor = self.isSelected ? outerCircleColor.cgColor(with: traitCollection) : UIColor.clear.cgColor
}

/// configures outer/inner circle frame,line widt and path
Expand Down
8 changes: 4 additions & 4 deletions Example/CardParts/CardPartRadioButtonCardController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ class CardPartRadioButtonCardController : CardPartsViewController {


let radioButton1 = CardPartRadioButton()
radioButton1.outerCircleColor = UIColor.red
radioButton1.outerCircleColor = UIColor.systemRed
radioButton1.outerCircleLineWidth = 2.0
radioButton1.tag = 1
radioButton1.isSelected = false
radioButton1.widthAnchor.constraint(equalToConstant: 20).isActive = true
radioButton1.heightAnchor.constraint(equalToConstant: 20).isActive = true

firstLabel.textColor = UIColor.red
firstLabel.textColor = UIColor.systemRed
firstLabel.text = "Not Selected"

[radioButton1, firstLabel].forEach { component in
Expand All @@ -57,14 +57,14 @@ class CardPartRadioButtonCardController : CardPartsViewController {
secondRowStackView.layoutMargins = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)

let radioButton2 = CardPartRadioButton()
radioButton2.outerCircleColor = UIColor.orange
radioButton2.outerCircleColor = UIColor.systemOrange
radioButton2.outerCircleLineWidth = 2.0
radioButton2.tag = 2
radioButton2.isSelected = true
radioButton2.widthAnchor.constraint(equalToConstant: 20).isActive = true
radioButton2.heightAnchor.constraint(equalToConstant: 20).isActive = true

secondLabel.textColor = UIColor.orange
secondLabel.textColor = UIColor.systemOrange
secondLabel.text = "Selected"

[radioButton2, secondLabel].forEach { component in
Expand Down

0 comments on commit a00ad4a

Please sign in to comment.