diff --git a/KYNavigationProgress/ProgressView.swift b/KYNavigationProgress/ProgressView.swift index 3169b27..d849d46 100644 --- a/KYNavigationProgress/ProgressView.swift +++ b/KYNavigationProgress/ProgressView.swift @@ -29,7 +29,7 @@ internal final class ProgressView: UIView { private let barWidthConstraint: NSLayoutConstraint - override var bounds: CGRect { + override var frame: CGRect { didSet { let tmpProgress = progress progress = tmpProgress diff --git a/KYNavigationProgress/UINavigationController+Progress.swift b/KYNavigationProgress/UINavigationController+Progress.swift index 4496c75..62e4812 100644 --- a/KYNavigationProgress/UINavigationController+Progress.swift +++ b/KYNavigationProgress/UINavigationController+Progress.swift @@ -20,15 +20,10 @@ public extension UINavigationController { Default is 2.0 */ public var progressHeight: CGFloat { - get { - return navigationBar.constraints - .filter{ $0.identifier == constraintIdentifier } - .first?.constant ?? 0.2 - } + get { return progressView.frame.height } set { - navigationBar.constraints - .filter{ $0.identifier == constraintIdentifier } - .first?.constant = newValue + progressView.frame.origin.y = navigationBar.frame.height - newValue + progressView.frame.size.height = newValue } } @@ -76,31 +71,12 @@ public extension UINavigationController { ) let progressView = ProgressView(frame: frame) - progressView.translatesAutoresizingMaskIntoConstraints = false - navigationBar.addSubview(progressView) - let progressHeightConstraint = NSLayoutConstraint( - item: progressView, - attribute: .Height, - relatedBy: .Equal, - toItem: nil, - attribute: .NotAnAttribute, - multiplier: 1, - constant: defaultHeight) - progressHeightConstraint.identifier = constraintIdentifier + progressView.autoresizingMask = [ + .FlexibleWidth, .FlexibleTopMargin + ] - navigationBar.addConstraint(progressHeightConstraint) - navigationBar.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat( - "H:|-0-[progressView]-0-|", - options: [], - metrics: nil, - views: ["progressView" : progressView])) - navigationBar.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat( - "V:[progressView]-0-|", - options: [], - metrics: nil, - views: ["progressView" : progressView])) return progressView } diff --git a/Sample/ViewController.swift b/Sample/ViewController.swift index cd92ab1..19e7fa7 100644 --- a/Sample/ViewController.swift +++ b/Sample/ViewController.swift @@ -37,6 +37,7 @@ class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. + navigationController?.progressHeight = 30 } override func didReceiveMemoryWarning() {