Commit 1b2c820b by Dmitriy Stepanets

Finished scroll indicator

parent ac9ecdf7
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
// //
import UIKit import UIKit
import SnapKit
private class InfoCardView:UIView { private class InfoCardView:UIView {
private let valueLabel = UILabel() private let valueLabel = UILabel()
...@@ -58,6 +59,9 @@ class CurrentForecastDetailsCell: UITableViewCell { ...@@ -58,6 +59,9 @@ class CurrentForecastDetailsCell: UITableViewCell {
private let stackView = UIStackView() private let stackView = UIStackView()
private let progressView = UIView() private let progressView = UIView()
private let progressIndicator = UIView() private let progressIndicator = UIView()
private let kIndicatorWidth:CGFloat = 16
private var indicatorWidthConstraint:Constraint?
private var indicatorLeftConstraint:Constraint?
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier) super.init(style: style, reuseIdentifier: reuseIdentifier)
...@@ -98,6 +102,7 @@ private extension CurrentForecastDetailsCell { ...@@ -98,6 +102,7 @@ private extension CurrentForecastDetailsCell {
scrollView.contentInset = .init(top: 0, left: 16, bottom: 0, right: 16) scrollView.contentInset = .init(top: 0, left: 16, bottom: 0, right: 16)
scrollView.showsVerticalScrollIndicator = false scrollView.showsVerticalScrollIndicator = false
scrollView.showsHorizontalScrollIndicator = false scrollView.showsHorizontalScrollIndicator = false
scrollView.delegate = self
contentView.addSubview(scrollView) contentView.addSubview(scrollView)
scrollView.snp.makeConstraints { (make) in scrollView.snp.makeConstraints { (make) in
...@@ -182,11 +187,23 @@ private extension CurrentForecastDetailsCell { ...@@ -182,11 +187,23 @@ private extension CurrentForecastDetailsCell {
progressIndicator.layer.cornerRadius = 2 progressIndicator.layer.cornerRadius = 2
progressIndicator.clipsToBounds = true progressIndicator.clipsToBounds = true
progressView.addSubview(progressIndicator) progressView.addSubview(progressIndicator)
progressIndicator.snp.makeConstraints { (make) in progressIndicator.snp.makeConstraints {[weak self] (make) in
make.height.equalToSuperview() make.height.equalToSuperview()
make.left.equalToSuperview() self?.indicatorLeftConstraint = make.left.equalToSuperview().constraint
make.centerY.equalToSuperview() make.centerY.equalToSuperview()
make.width.equalTo(16) self?.indicatorWidthConstraint = make.width.equalTo(kIndicatorWidth).constraint
} }
} }
} }
//MARK:- UIScrollView Delegate
extension CurrentForecastDetailsCell: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let totalContentWidth = scrollView.contentSize.width + scrollView.contentInset.left + scrollView.contentInset.right
let scrollProgress = (scrollView.contentOffset.x + scrollView.contentInset.left)
/ (totalContentWidth - scrollView.bounds.width)
let multiplier = (progressView.bounds.width - kIndicatorWidth) / kIndicatorWidth
indicatorLeftConstraint?.layoutConstraints.first?.constant = multiplier * scrollProgress * kIndicatorWidth
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment