diff options
author | Roopesh Chander <roop@roopc.net> | 2018-11-06 16:48:53 +0530 |
---|---|---|
committer | Roopesh Chander <roop@roopc.net> | 2018-11-06 16:49:09 +0530 |
commit | 1a43ad6e39bb52ef4c501e73c58988cdd3bf43d1 (patch) | |
tree | 6fd9270e6c18ef7016a9c9aec721ae4349bcba51 /WireGuard/WireGuard/UI/iOS/ScrollableLabel.swift | |
parent | Tunnel view model: Peers in a configuation may not share the same public key (diff) | |
download | wireguard-apple-1a43ad6e39bb52ef4c501e73c58988cdd3bf43d1.tar.xz wireguard-apple-1a43ad6e39bb52ef4c501e73c58988cdd3bf43d1.zip |
Tunnel detail: Refactor out the label scrolling into a separate UI class
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r-- | WireGuard/WireGuard/UI/iOS/ScrollableLabel.swift | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/ScrollableLabel.swift b/WireGuard/WireGuard/UI/iOS/ScrollableLabel.swift new file mode 100644 index 0000000..780d6c8 --- /dev/null +++ b/WireGuard/WireGuard/UI/iOS/ScrollableLabel.swift @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: MIT +// Copyright © 2018 WireGuard LLC. All Rights Reserved. + +import UIKit + +class ScrollableLabel: UIScrollView { + var text: String { + get { return label.text ?? "" } + set(value) { label.text = value } + } + var textColor: UIColor { + get { return label.textColor } + set(value) { label.textColor = value } + } + + private let label: UILabel + + init() { + let label = UILabel() + label.translatesAutoresizingMaskIntoConstraints = false + label.textAlignment = .right + self.label = label + + super.init(frame: CGRect.zero) + + self.isDirectionalLockEnabled = true + self.showsHorizontalScrollIndicator = false + self.showsVerticalScrollIndicator = false + + addSubview(label) + label.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate([ + label.leftAnchor.constraint(equalTo: self.contentLayoutGuide.leftAnchor), + label.topAnchor.constraint(equalTo: self.contentLayoutGuide.topAnchor), + label.bottomAnchor.constraint(equalTo: self.contentLayoutGuide.bottomAnchor), + label.rightAnchor.constraint(equalTo: self.contentLayoutGuide.rightAnchor), + label.heightAnchor.constraint(equalTo: self.heightAnchor), + ]) + // If label has less content, it should expand to fit the scrollView, + // so that right-alignment works in the label. + let expandToFitValueLabelConstraint = NSLayoutConstraint(item: label, attribute: .width, relatedBy: .equal, + toItem: self, attribute: .width, multiplier: 1, constant: 0) + expandToFitValueLabelConstraint.priority = .defaultLow + 1 + expandToFitValueLabelConstraint.isActive = true + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} |