[ios] fix UIView+AddSeparator to support the top and bottom positions

Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
Kiryl Kaveryn 2024-11-05 16:18:02 +04:00 committed by Kiryl Kaveryn
parent 2ad85fbcf7
commit 916d787e4d

View file

@ -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
}
}
}