Skip to content

Commit

Permalink
Correctly refresh button styles if changes are made in code
Browse files Browse the repository at this point in the history
  • Loading branch information
Fawxy committed Jun 20, 2017
1 parent ac24d5c commit 7cbe3a8
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CBPinEntryView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'CBPinEntryView'
s.version = '1.3.2'
s.version = '1.3.3'
s.summary = 'A view for entering arbitrary length numerical pins or codes written in Swift 3.0.'

# This description is used to generate tags and improve search results.
Expand Down
68 changes: 60 additions & 8 deletions CBPinEntryView/Classes/CBPinEntryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,55 @@ public protocol CBPinEntryViewDelegate {

@IBInspectable open var length: Int = CBPinEntryViewDefaults.length

@IBInspectable open var entryCornerRadius: CGFloat = CBPinEntryViewDefaults.entryCornerRadius
@IBInspectable open var entryCornerRadius: CGFloat = CBPinEntryViewDefaults.entryCornerRadius {
didSet {
if oldValue != entryCornerRadius {
updateButtonStyles()
}
}
}

@IBInspectable open var entryBorderWidth: CGFloat = CBPinEntryViewDefaults.entryBorderWidth {
didSet {
if oldValue != entryBorderWidth {
updateButtonStyles()
}
}
}

@IBInspectable open var entryDefaultBorderColour: UIColor = CBPinEntryViewDefaults.entryDefaultBorderColour {
didSet {
if oldValue != entryDefaultBorderColour {
updateButtonStyles()
}
}
}

@IBInspectable open var entryBorderColour: UIColor = CBPinEntryViewDefaults.entryBorderColour {
didSet {
if oldValue != entryBorderColour {
updateButtonStyles()
}
}
}

@IBInspectable open var entryBorderWidth: CGFloat = CBPinEntryViewDefaults.entryBorderWidth
@IBInspectable open var entryDefaultBorderColour: UIColor = CBPinEntryViewDefaults.entryDefaultBorderColour
@IBInspectable open var entryBorderColour: UIColor = CBPinEntryViewDefaults.entryBorderColour
@IBInspectable open var entryErrorBorderColour: UIColor = CBPinEntryViewDefaults.entryErrorColour

@IBInspectable open var entryBackgroundColour: UIColor = CBPinEntryViewDefaults.entryBackgroundColour
@IBInspectable open var entryTextColour: UIColor = CBPinEntryViewDefaults.entryTextColour
@IBInspectable open var entryBackgroundColour: UIColor = CBPinEntryViewDefaults.entryBackgroundColour {
didSet {
if oldValue != entryBackgroundColour {
updateButtonStyles()
}
}
}

@IBInspectable open var entryTextColour: UIColor = CBPinEntryViewDefaults.entryTextColour {
didSet {
if oldValue != entryTextColour {
updateButtonStyles()
}
}
}

@IBInspectable open var entryFont: UIFont = CBPinEntryViewDefaults.entryFont

Expand Down Expand Up @@ -89,9 +129,9 @@ public protocol CBPinEntryViewDelegate {
private func createButtons() {
for i in 0..<length {
let button = UIButton()
button.backgroundColor = UIColor.white
button.backgroundColor = entryBackgroundColour
button.setTitleColor(entryTextColour, for: .normal)
button.titleLabel!.font = entryFont
button.titleLabel?.font = entryFont

button.layer.cornerRadius = entryCornerRadius
button.layer.borderColor = entryDefaultBorderColour.cgColor
Expand All @@ -106,6 +146,18 @@ public protocol CBPinEntryViewDelegate {
}
}

private func updateButtonStyles() {
for button in entryButtons {
button.backgroundColor = entryBackgroundColour
button.setTitleColor(entryTextColour, for: .normal)
button.titleLabel?.font = entryFont

button.layer.cornerRadius = entryCornerRadius
button.layer.borderColor = entryDefaultBorderColour.cgColor
button.layer.borderWidth = entryBorderWidth
}
}

@objc private func didPressCodeButton(_ sender: UIButton) {
errorMode = false

Expand Down

0 comments on commit 7cbe3a8

Please sign in to comment.