浏览代码

flex label in separate file

nayooti 5 年之前
父节点
当前提交
bcf4afb057
共有 3 个文件被更改,包括 87 次插入81 次删除
  1. 4 0
      deltachat-ios.xcodeproj/project.pbxproj
  2. 0 81
      deltachat-ios/View/EmptyStateLabel.swift
  3. 83 0
      deltachat-ios/View/FlexLabel.swift

+ 4 - 0
deltachat-ios.xcodeproj/project.pbxproj

@@ -156,6 +156,7 @@
 		AEACE2DF1FB3246400DCDD78 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2DE1FB3246400DCDD78 /* Message.swift */; };
 		AEACE2E31FB32B5C00DCDD78 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2E21FB32B5C00DCDD78 /* Constants.swift */; };
 		AEACE2E51FB32E1900DCDD78 /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEACE2E41FB32E1900DCDD78 /* Utils.swift */; };
+		AEB54C7F246DBA610004624C /* FlexLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEB54C7E246DBA610004624C /* FlexLabel.swift */; };
 		AEC67A1C241CE9E4007DDBE1 /* AppStateRestorer.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC67A1B241CE9E4007DDBE1 /* AppStateRestorer.swift */; };
 		AEC67A1E241FCFE0007DDBE1 /* ChatListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AEC67A1D241FCFE0007DDBE1 /* ChatListViewModel.swift */; };
 		AECEF03E244F2D55006C90DA /* QrPageController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AECEF03D244F2D55006C90DA /* QrPageController.swift */; };
@@ -442,6 +443,7 @@
 		AEACE2DE1FB3246400DCDD78 /* Message.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
 		AEACE2E21FB32B5C00DCDD78 /* Constants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
 		AEACE2E41FB32E1900DCDD78 /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
+		AEB54C7E246DBA610004624C /* FlexLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlexLabel.swift; sourceTree = "<group>"; };
 		AEC67A1B241CE9E4007DDBE1 /* AppStateRestorer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStateRestorer.swift; sourceTree = "<group>"; };
 		AEC67A1D241FCFE0007DDBE1 /* ChatListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatListViewModel.swift; sourceTree = "<group>"; };
 		AECEF03D244F2D55006C90DA /* QrPageController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QrPageController.swift; sourceTree = "<group>"; };
@@ -941,6 +943,7 @@
 				30F9B9EB235F2116006E7ACF /* MessageCounter.swift */,
 				305FE03523A81B4C0053BE90 /* EmptyStateLabel.swift */,
 				AEFBE22E23FEF23D0045327A /* ProviderInfoCell.swift */,
+				AEB54C7E246DBA610004624C /* FlexLabel.swift */,
 			);
 			path = View;
 			sourceTree = "<group>";
@@ -1420,6 +1423,7 @@
 				305961F12346125100C80F33 /* ContactMessageCell.swift in Sources */,
 				AE851AD0227DF50900ED86F0 /* GroupChatDetailViewController.swift in Sources */,
 				305961D12346125100C80F33 /* Bundle+Extensions.swift in Sources */,
+				AEB54C7F246DBA610004624C /* FlexLabel.swift in Sources */,
 				305962002346125100C80F33 /* MessagesCollectionView.swift in Sources */,
 				7A451DB01FB1F84900177250 /* AppCoordinator.swift in Sources */,
 				AE38B31822672DFC00EC37A1 /* ActionCell.swift in Sources */,

+ 0 - 81
deltachat-ios/View/EmptyStateLabel.swift

@@ -39,84 +39,3 @@ class EmptyStateLabel: FlexLabel {
     }
 }
 
-/// view that contains a label (horizontally centered) and
-/// allows it's label to grow/shrink within it's available space
-class FlexLabel: UIView {
-
-    var text: String? {
-        set {
-            label.text = newValue
-        }
-        get {
-            return label.text
-        }
-    }
-
-    var textColor: UIColor {
-        set {
-            label.textColor = newValue
-        }
-        get {
-            return label.textColor
-        }
-    }
-
-    var attributedText: NSAttributedString? {
-        set {
-            label.attributedText = newValue
-        }
-        get {
-            return label.attributedText
-        }
-    }
-
-    lazy var label: UILabel = {
-        let label = PaddingLabel(top: 15, left: 15, bottom: 15, right: 15)
-        label.numberOfLines = 0
-        return label
-    }()
-
-    init() {
-        super.init(frame: .zero)
-        setupSubviews()
-    }
-
-    required init?(coder: NSCoder) {
-        fatalError("init(coder:) has not been implemented")
-    }
-
-    private func setupSubviews() {
-        addSubview(label)
-        label.translatesAutoresizingMaskIntoConstraints = false
-        label.centerYAnchor.constraint(equalTo: centerYAnchor, constant: 0).isActive = true
-        label.centerXAnchor.constraint(equalTo: centerXAnchor, constant: 0).isActive = true
-        label.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
-        label.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true
-        label.widthAnchor.constraint(lessThanOrEqualTo: widthAnchor, multiplier: 0.95).isActive = true
-    }
-
-    class PaddingLabel: UILabel {
-        let insets: UIEdgeInsets
-
-        init(top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) {
-            self.insets = UIEdgeInsets(top: top, left: left, bottom: bottom, right: right)
-            super.init(frame: .zero)
-        }
-
-        required init?(coder: NSCoder) {
-            fatalError("init(coder:) has not been implemented")
-        }
-
-        override func drawText(in rect: CGRect) {
-            super.drawText(in: rect.inset(by: insets))
-        }
-
-        override var intrinsicContentSize: CGSize {
-            let size = super.intrinsicContentSize
-            return CGSize(
-                width: size.width + insets.left + insets.right,
-                height: size.height + insets.top + insets.bottom
-            )
-        }
-    }
-}

+ 83 - 0
deltachat-ios/View/FlexLabel.swift

@@ -0,0 +1,83 @@
+import UIKit
+
+/// view that contains a label (horizontally centered) and
+/// allows it's label to grow/shrink within it's available space
+class FlexLabel: UIView {
+
+    var text: String? {
+        set {
+            label.text = newValue
+        }
+        get {
+            return label.text
+        }
+    }
+
+    var textColor: UIColor {
+        set {
+            label.textColor = newValue
+        }
+        get {
+            return label.textColor
+        }
+    }
+
+    var attributedText: NSAttributedString? {
+        set {
+            label.attributedText = newValue
+        }
+        get {
+            return label.attributedText
+        }
+    }
+
+    lazy var label: UILabel = {
+        let label = PaddingLabel(top: 15, left: 15, bottom: 15, right: 15)
+        label.numberOfLines = 0
+        return label
+    }()
+
+    init() {
+        super.init(frame: .zero)
+        setupSubviews()
+    }
+
+    required init?(coder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+
+    private func setupSubviews() {
+        addSubview(label)
+        label.translatesAutoresizingMaskIntoConstraints = false
+        label.centerYAnchor.constraint(equalTo: centerYAnchor, constant: 0).isActive = true
+        label.centerXAnchor.constraint(equalTo: centerXAnchor, constant: 0).isActive = true
+        label.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
+        label.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true
+        label.widthAnchor.constraint(lessThanOrEqualTo: widthAnchor, multiplier: 0.95).isActive = true
+    }
+
+    class PaddingLabel: UILabel {
+        let insets: UIEdgeInsets
+
+        init(top: CGFloat, left: CGFloat, bottom: CGFloat, right: CGFloat) {
+            self.insets = UIEdgeInsets(top: top, left: left, bottom: bottom, right: right)
+            super.init(frame: .zero)
+        }
+
+        required init?(coder: NSCoder) {
+            fatalError("init(coder:) has not been implemented")
+        }
+
+        override func drawText(in rect: CGRect) {
+            super.drawText(in: rect.inset(by: insets))
+        }
+
+        override var intrinsicContentSize: CGSize {
+            let size = super.intrinsicContentSize
+            return CGSize(
+                width: size.width + insets.left + insets.right,
+                height: size.height + insets.top + insets.bottom
+            )
+        }
+    }
+}