Skip to content

Commit

Permalink
Merge pull request #33 from kazuhiro4949/feature/fixBugToAccessUnderl…
Browse files Browse the repository at this point in the history
…ineHeight

fix bug to access underline height
  • Loading branch information
kazuhiro4949 authored Jan 5, 2018
2 parents 6c5fb31 + 98b4204 commit 886986d
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions PagingKit/UnderlineFocusView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,43 @@ public class UnderlineFocusView: UIView {
/// The color of underline
public var underlineColor = UIColor.pk.focusRed
/// The color of underline
public var underlineHeight = CGFloat(4)
public var underlineHeight = CGFloat(4) {
didSet {
heightConstraint.constant = underlineHeight
}
}

private let heightConstraint: NSLayoutConstraint
private let underlineView = UIView()

required public init?(coder aDecoder: NSCoder) {
heightConstraint = NSLayoutConstraint(
item: underlineView,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .height, multiplier: 1, constant: underlineHeight
)
super.init(coder: aDecoder)
setup()
}

override public init(frame: CGRect) {
heightConstraint = NSLayoutConstraint(
item: underlineView,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .height, multiplier: 1, constant: underlineHeight
)
super.init(frame: frame)
setup()
}

private func setup() {
addSubview(underlineView)
underlineView.translatesAutoresizingMaskIntoConstraints = false
addConstraint(NSLayoutConstraint(
item: underlineView,
attribute: .height,
relatedBy: .equal,
toItem: nil,
attribute: .height, multiplier: 1, constant: 4))
addConstraint(heightConstraint)
let constraints = [.bottom, .leading, .trailing].anchor(from: underlineView, to: self)
addConstraints(constraints)
underlineView.backgroundColor = underlineColor
Expand Down

0 comments on commit 886986d

Please sign in to comment.