forked from organicmaps/organicmaps-tmp
[ios] fix UIView+AddSeparator to support the top and bottom positions
Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
parent
2ad85fbcf7
commit
916d787e4d
1 changed files with 15 additions and 4 deletions
|
@ -1,17 +1,28 @@
|
|||
extension UIView {
|
||||
func addSeparator(thickness: CGFloat = 1.0,
|
||||
color: UIColor? = StyleManager.shared.theme?.colors.blackDividers,
|
||||
enum SeparatorPosition {
|
||||
case top
|
||||
case bottom
|
||||
}
|
||||
|
||||
func addSeparator(_ position: SeparatorPosition = .top,
|
||||
thickness: CGFloat = 1.0,
|
||||
insets: UIEdgeInsets = .zero) {
|
||||
let lineView = UIView()
|
||||
lineView.backgroundColor = color
|
||||
lineView.setStyleAndApply("Divider")
|
||||
lineView.isUserInteractionEnabled = false
|
||||
lineView.translatesAutoresizingMaskIntoConstraints = false
|
||||
addSubview(lineView)
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
lineView.heightAnchor.constraint(equalToConstant: thickness),
|
||||
lineView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: insets.left),
|
||||
lineView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -insets.right),
|
||||
lineView.topAnchor.constraint(equalTo: topAnchor, constant: insets.top),
|
||||
])
|
||||
switch position {
|
||||
case .top:
|
||||
lineView.topAnchor.constraint(equalTo: topAnchor, constant: insets.top).isActive = true
|
||||
case .bottom:
|
||||
lineView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -insets.bottom).isActive = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue