Skip to content

Commit

Permalink
properly update appearance for badge elements
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusGeffarth committed Jan 1, 2019
1 parent 722f517 commit f6e1a9f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion LGSegmentedControl.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'LGSegmentedControl'
s.version = '1.2'
s.version = '1.2.1'
s.summary = 'A prettier and highly customizable UISegmentedControl'

# This description is used to generate tags and improve search results.
Expand Down
9 changes: 6 additions & 3 deletions LGSegmentedControl/Classes/LGSegment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class LGSegment {
badgeLabel.topAnchor .constraint(equalTo: badgeView.topAnchor, constant: 0.5).isActive = true
badgeLabel.bottomAnchor .constraint(equalTo: badgeView.bottomAnchor, constant:-0.5).isActive = true

badgeView.leadingAnchor .constraint(equalTo: titleLabel.trailingAnchor, constant: 0).isActive = true
badgeView.leadingAnchor .constraint(equalTo: titleLabel.trailingAnchor, constant: -2).isActive = true
badgeView.bottomAnchor .constraint(equalTo: titleLabel.topAnchor , constant: 6).isActive = true
let badgeViewSize: CGFloat = 16
badgeView.heightAnchor .constraint(greaterThanOrEqualToConstant: badgeViewSize).isActive = true
Expand All @@ -129,13 +129,16 @@ class LGSegment {
func updateAppearance(with options: LGSegmentOptions, animated: Bool? = nil) {
self.options = options
UIView.animate(withDuration: animated ?? options.animateStateChange ? 0.1 : 0) {
// status-related
// status
self.titleLabel.textColor = self.textColor
self.backgroundView.backgroundColor = self.backgroundColor
// badge view
self.badgeView.isHidden = self.badgeCount == nil
self.badgeView.backgroundColor = options.badgeColor.background
self.badgeLabel.textColor = options.badgeColor.text
// others
self.backgroundView.layer.cornerRadius = options.cornerRadius
self.titleLabel.font = options.font
self.badgeView.isHidden = self.badgeCount == nil
}
badgeLabel.text = badgeCount?.string ?? ""
}
Expand Down

0 comments on commit f6e1a9f

Please sign in to comment.