瀏覽代碼

restrict size of webxdc labels, different font size, weight and positioning of the webxdc label

cyberta 2 年之前
父節點
當前提交
7702b6c216

+ 15 - 0
DcCore/DcCore/Extensions/UIView+Extensions.swift

@@ -119,6 +119,21 @@ public extension UIView {
         return constraint
     }
 
+    func constraintAlignBottomMaxTo(_ view: UIView, paddingBottom: CGFloat = 0.0, priority: UILayoutPriority? = .none) -> NSLayoutConstraint {
+        let constraint = NSLayoutConstraint(
+            item: self,
+            attribute: .bottom,
+            relatedBy: .lessThanOrEqual,
+            toItem: view,
+            attribute: .bottom,
+            multiplier: 1.0,
+            constant: -paddingBottom)
+        if let priority = priority {
+            constraint.priority = priority
+        }
+        return constraint
+    }
+
     func constraintAlignLeadingTo(_ view: UIView, paddingLeading: CGFloat = 0.0, priority: UILayoutPriority? = .none) -> NSLayoutConstraint {
         let constraint = NSLayoutConstraint(
             item: self,

+ 1 - 1
deltachat-ios/Controller/WebxdcSelector.swift

@@ -24,7 +24,7 @@ class WebxdcSelector: UIViewController {
         let layout = GridCollectionViewFlowLayout()
         layout.minimumLineSpacing = gridDefaultSpacing
         layout.minimumInteritemSpacing = gridDefaultSpacing
-        layout.format = .rect(ratio: 1.2)
+        layout.format = .rect(ratio: 1.3)
         return layout
     }()
 

+ 18 - 3
deltachat-ios/View/Cell/WebxdcGridCell.swift

@@ -7,6 +7,14 @@ class WebxdcGridCell: UICollectionViewCell {
 
     weak var item: GalleryItem?
 
+    private var font: UIFont {
+        let regularFont = UIFont.preferredFont(forTextStyle: .subheadline)
+        if regularFont.pointSize > 28 {
+            return UIFont.systemFont(ofSize: 28)
+        }
+        return regularFont
+    }
+
     private lazy var imageView: SDAnimatedImageView = {
         let view = SDAnimatedImageView()
         view.contentMode = .scaleAspectFill
@@ -21,7 +29,7 @@ class WebxdcGridCell: UICollectionViewCell {
     private lazy var descriptionLabel: UILabel = {
         let label = UILabel()
         label.translatesAutoresizingMaskIntoConstraints = false
-        label.font = UIFont.preferredFont(for: .caption1, weight: .light)
+        label.font = font
         label.lineBreakMode = .byTruncatingTail
         label.textColor = DcColors.defaultInverseColor
         label.backgroundColor = DcColors.defaultTransparentBackgroundColor
@@ -58,8 +66,8 @@ class WebxdcGridCell: UICollectionViewCell {
             descriptionLabel.constraintAlignTrailingMaxTo(contentView),
             descriptionLabel.constraintCenterXTo(contentView),
             descriptionLabel.widthAnchor.constraint(lessThanOrEqualTo: imageView.widthAnchor),
-            descriptionLabel.constraintAlignBottomTo(contentView),
-            descriptionLabel.constraintToBottomOf(imageView),
+            descriptionLabel.constraintToBottomOf(imageView, paddingTop: 4),
+            descriptionLabel.constraintAlignBottomMaxTo(contentView)
         ])
     }
 
@@ -78,4 +86,11 @@ class WebxdcGridCell: UICollectionViewCell {
             imageView.alpha = newValue ? 0.75 : 1.0
         }
     }
+
+    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
+        if previousTraitCollection?.preferredContentSizeCategory !=
+            traitCollection.preferredContentSizeCategory {
+                descriptionLabel.font = font
+        }
+    }
 }