aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/iOS/SharedViews/ScrollableLabel.swift
diff options
context:
space:
mode:
Diffstat (limited to 'WireGuard/WireGuard/UI/iOS/SharedViews/ScrollableLabel.swift')
-rw-r--r--WireGuard/WireGuard/UI/iOS/SharedViews/ScrollableLabel.swift48
1 files changed, 48 insertions, 0 deletions
diff --git a/WireGuard/WireGuard/UI/iOS/SharedViews/ScrollableLabel.swift b/WireGuard/WireGuard/UI/iOS/SharedViews/ScrollableLabel.swift
new file mode 100644
index 00000000..bd6f5471
--- /dev/null
+++ b/WireGuard/WireGuard/UI/iOS/SharedViews/ScrollableLabel.swift
@@ -0,0 +1,48 @@
+// 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 }
+ }
+
+ let label: UILabel = {
+ let label = UILabel()
+ label.translatesAutoresizingMaskIntoConstraints = false
+ label.textAlignment = .right
+ return label
+ }()
+
+ init() {
+ super.init(frame: CGRect.zero)
+
+ isDirectionalLockEnabled = true
+ showsHorizontalScrollIndicator = false
+ showsVerticalScrollIndicator = false
+
+ addSubview(label)
+ label.translatesAutoresizingMaskIntoConstraints = false
+ NSLayoutConstraint.activate([
+ label.leftAnchor.constraint(equalTo: contentLayoutGuide.leftAnchor),
+ label.topAnchor.constraint(equalTo: contentLayoutGuide.topAnchor),
+ label.bottomAnchor.constraint(equalTo: contentLayoutGuide.bottomAnchor),
+ label.rightAnchor.constraint(equalTo: contentLayoutGuide.rightAnchor),
+ label.heightAnchor.constraint(equalTo: heightAnchor)
+ ])
+
+ 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")
+ }
+}