forked from HeathWang/HWPanModal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
170 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
SwiftDemo/ControllerExample/Indicator/CustomIndicatorController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// CustomIndicatorController.swift | ||
// SwiftDemo | ||
// | ||
// Created by heath wang on 2019/9/4. | ||
// Copyright © 2019 wangcongling. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
import HWPanModal | ||
|
||
enum IndicatorStyle { | ||
case changeColor, text, immobile | ||
} | ||
|
||
class IndicatorPopViewController: UIViewController { | ||
|
||
private let style: IndicatorStyle | ||
|
||
init(style: IndicatorStyle) { | ||
self.style = style | ||
super.init(nibName: nil, bundle: nil) | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
view.backgroundColor = UIColor(displayP3Red: 0, green: 1, blue: 8, alpha: 1) | ||
} | ||
|
||
override func longFormHeight() -> PanModalHeight { | ||
return PanModalHeight(type: .topInset, height: 44) | ||
} | ||
|
||
override func customIndicatorView() -> (UIView & HWPanModalIndicatorProtocol)? { | ||
switch style { | ||
case .changeColor: | ||
let indicatorView = HWPanIndicatorView() | ||
indicatorView.indicatorColor = view.backgroundColor! | ||
return indicatorView | ||
case .text: | ||
return TextIndicatorView() | ||
case .immobile: | ||
return ImmobileIndicatorView() | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// | ||
// IndicatorView.swift | ||
// SwiftDemo | ||
// | ||
// Created by heath wang on 2019/9/4. | ||
// Copyright © 2019 wangcongling. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
import HWPanModal | ||
|
||
class TextIndicatorView: UIView, HWPanModalIndicatorProtocol { | ||
|
||
lazy var stateLabel: UILabel = { | ||
let label = UILabel() | ||
label.textAlignment = .center | ||
label.font = UIFont.systemFont(ofSize: 14) | ||
label.textColor = UIColor.darkText | ||
return label | ||
}() | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
|
||
addSubview(stateLabel) | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
} | ||
|
||
extension TextIndicatorView { | ||
|
||
func didChange(to state: HWIndicatorState) { | ||
switch state { | ||
case .normal: | ||
stateLabel.textColor = .white | ||
stateLabel.text = "Please pull down to dismiss" | ||
case .pull: | ||
stateLabel.textColor = UIColor(displayP3Red: 1, green: 0.200, blue: 0, alpha: 1) | ||
stateLabel.text = "Keep pull down to dismiss" | ||
default: break | ||
} | ||
|
||
} | ||
|
||
func indicatorSize() -> CGSize { | ||
return CGSize(width: 200, height: 18) | ||
} | ||
|
||
func setupSubviews() { | ||
stateLabel.frame = bounds | ||
} | ||
} | ||
|
||
class ImmobileIndicatorView: UIView { | ||
|
||
lazy var lineView: UIView = { | ||
let line = UIView() | ||
line.backgroundColor = UIColor.lightGray | ||
line.layer.cornerRadius = 4 | ||
return line | ||
}() | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
addSubview(lineView) | ||
} | ||
|
||
required init?(coder aDecoder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
} | ||
|
||
extension ImmobileIndicatorView: HWPanModalIndicatorProtocol { | ||
|
||
func didChange(to state: HWIndicatorState) {} | ||
|
||
func indicatorSize() -> CGSize { | ||
return CGSize(width: 45, height: 8) | ||
} | ||
|
||
func setupSubviews() { | ||
lineView.frame = CGRect(x: 0, y: 0, width: indicatorSize().width, height: indicatorSize().height) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters