From e100025c6d0d12dbda1e6dd00d49174c06ac7ff4 Mon Sep 17 00:00:00 2001
From: Lee <18611401994@163.com>
Date: Thu, 13 Aug 2020 19:53:38 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98=E7=BB=A7=E7=BB=AD=E5=AE=8C?=
=?UTF-8?q?=E5=96=84Debug=E6=AE=B5=E8=90=BD=E7=9B=B8=E5=85=B3=E7=9A=84?=
=?UTF-8?q?=E8=AE=BE=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Demo/Demo/Debug/Debug.storyboard | 307 +++++++++++++++++-
Demo/Demo/Debug/DebugLabelView.swift | 34 +-
.../Demo/Debug/DebugLabelViewController.swift | 61 ++--
3 files changed, 376 insertions(+), 26 deletions(-)
diff --git a/Demo/Demo/Debug/Debug.storyboard b/Demo/Demo/Debug/Debug.storyboard
index 9f653b8..3234710 100644
--- a/Demo/Demo/Debug/Debug.storyboard
+++ b/Demo/Demo/Debug/Debug.storyboard
@@ -16,7 +16,7 @@
-
+
@@ -719,10 +719,10 @@
-
+
-
+
@@ -806,6 +806,293 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -955,10 +1242,14 @@
+
+
+
+
@@ -967,12 +1258,22 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/Demo/Demo/Debug/DebugLabelView.swift b/Demo/Demo/Debug/DebugLabelView.swift
index 7f01623..7d5d37c 100644
--- a/Demo/Demo/Debug/DebugLabelView.swift
+++ b/Demo/Demo/Debug/DebugLabelView.swift
@@ -82,6 +82,8 @@ class DebugLabelView: UIView {
label.minimumScaleFactor = value
minimumScaleFactorLabel.text = String(format: "%.2f", value)
minimumScaleFactorSlider.value = .init(value)
+ label.adjustsFontSizeToFitWidth.toggle()
+ label.adjustsFontSizeToFitWidth.toggle()
}
}
var allowsDefaultTighteningForTruncation: Bool = false {
@@ -108,6 +110,22 @@ class DebugLabelView: UIView {
}
}
+ var minimumLineHeight: CGFloat = 0 {
+ didSet {
+ let value = minimumLineHeight
+ minimumLineHeightLabel.text = String(format: "%.2f", value)
+ minimumLineHeightSlider.value = .init(value)
+ }
+ }
+
+ var maximumLineHeight: CGFloat = 0 {
+ didSet {
+ let value = maximumLineHeight
+ maximumLineHeightLabel.text = String(format: "%.2f", value)
+ maximumLineHeightSlider.value = .init(value)
+ }
+ }
+
@IBOutlet private weak var label: UILabel!
@IBOutlet private weak var widthLayoutConstraint: NSLayoutConstraint!
@@ -141,14 +159,26 @@ class DebugLabelView: UIView {
@IBOutlet private weak var minimumScaleFactorLabel: UILabel!
@IBOutlet private weak var minimumScaleFactorSlider: UISlider!
@IBOutlet private weak var allowsDefaultTighteningForTruncationSwitch: UISwitch!
-
/// Page 5
@IBOutlet private weak var lineSpacingLabel: UILabel!
@IBOutlet private weak var lineSpacingSlider: UISlider!
@IBOutlet private weak var lineHeightMultipleLabel: UILabel!
@IBOutlet private weak var lineHeightMultipleSlider: UISlider!
+ @IBOutlet private weak var minimumLineHeightLabel: UILabel!
+ @IBOutlet private weak var minimumLineHeightSlider: UISlider!
+ @IBOutlet private weak var maximumLineHeightLabel: UILabel!
+ @IBOutlet private weak var maximumLineHeightSlider: UISlider!
+ @IBOutlet private weak var paragraphSpacingLabel: UILabel!
+ @IBOutlet private weak var paragraphSpacingSlider: UISlider!
+ @IBOutlet private weak var paragraphSpacingBeforeLabel: UILabel!
+ @IBOutlet private weak var paragraphSpacingBeforeSlider: UISlider!
+ @IBOutlet private weak var firstLineHeadIndentLabel: UILabel!
+ @IBOutlet private weak var firstLineHeadIndentSlider: UISlider!
+ @IBOutlet private weak var headIndentLabel: UILabel!
+ @IBOutlet private weak var headIndentSlider: UISlider!
+ @IBOutlet private weak var tailIndentLabel: UILabel!
+ @IBOutlet private weak var tailIndentSlider: UISlider!
- private var old: Debug.Label?
private var labelBoundsObservation: NSKeyValueObservation?
override func awakeFromNib() {
diff --git a/Demo/Demo/Debug/DebugLabelViewController.swift b/Demo/Demo/Debug/DebugLabelViewController.swift
index dcab590..a697e77 100644
--- a/Demo/Demo/Debug/DebugLabelViewController.swift
+++ b/Demo/Demo/Debug/DebugLabelViewController.swift
@@ -14,23 +14,7 @@ private let key = "com.debug.label"
class DebugLabelViewController: ViewController {
private var info: Debug.Label = .init() {
- didSet {
- if let value = info.lineSpacing {
- paragraphs.removeAll(where: { $0 == .lineSpacing(0) })
- paragraphs.append(.lineSpacing(value))
-
- } else {
- paragraphs.removeAll(where: { $0 == .lineSpacing(0) })
- }
- if let value = info.lineHeightMultiple {
- paragraphs.removeAll(where: { $0 == .lineHeightMultiple(0) })
- paragraphs.append(.lineHeightMultiple(value))
-
- } else {
- paragraphs.removeAll(where: { $0 == .lineHeightMultiple(0) })
- }
- container.set(info: info)
- }
+ didSet { set(info: info) }
}
private var attributes: [AttributedString.Attribute] = []
@@ -38,6 +22,7 @@ class DebugLabelViewController: ViewController {
private var attributedString: AttributedString = """
我的名字叫李响,我的手机号码是18611401994,我的电子邮件地址是18611401994@163.com,现在是2020/06/28 20:30。我的GitHub主页是https://github.com/lixiang1994。欢迎来Star! \("点击联系我", .action({ }))
"""
+
override func viewDidLoad() {
super.viewDidLoad()
@@ -55,6 +40,24 @@ class DebugLabelViewController: ViewController {
self.info = info
}
+ private func set(info: Debug.Label) {
+ if let value = info.lineSpacing {
+ paragraphs.removeAll(where: { $0 == .lineSpacing(0) })
+ paragraphs.append(.lineSpacing(value))
+
+ } else {
+ paragraphs.removeAll(where: { $0 == .lineSpacing(0) })
+ }
+ if let value = info.lineHeightMultiple {
+ paragraphs.removeAll(where: { $0 == .lineHeightMultiple(0) })
+ paragraphs.append(.lineHeightMultiple(value))
+
+ } else {
+ paragraphs.removeAll(where: { $0 == .lineHeightMultiple(0) })
+ }
+ container.set(info: info)
+ }
+
private func update() {
container.set(text: .init(
attributedString,
@@ -112,10 +115,6 @@ class DebugLabelViewController: ViewController {
}
@IBAction func minimumScaleFactorSlider(_ sender: UISlider) {
info.minimumScaleFactor = .init(sender.value)
- // 需要关闭再开启才会更新
-// container.aLabel.adjustsFontSizeToFitWidth.toggle()
-// container.aLabel.adjustsFontSizeToFitWidth.toggle()
- update()
}
@IBAction func allowsDefaultTighteningForTruncationSwitchAction(_ sender: UISwitch) {
info.allowsDefaultTighteningForTruncation = sender.isOn
@@ -133,6 +132,26 @@ class DebugLabelViewController: ViewController {
info.lineHeightMultiple = .init(sender.value)
update()
}
+
+ @IBAction func minimumLineHeightSliderAction(_ sender: UISlider) {
+ }
+ @IBAction func maximumLineHeightSliderAction(_ sender: UISlider) {
+ }
+
+ @IBAction func paragraphSpacingSliderAction(_ sender: UISlider) {
+ }
+ @IBAction func paragraphSpacingBeforeSliderAction(_ sender: UISlider) {
+ }
+
+ @IBAction func firstLineHeadIndentSliderAction(_ sender: UISlider) {
+ }
+
+ @IBAction func headIndentSliderAction(_ sender: UISlider) {
+ }
+
+ @IBAction func tailIndentSliderAction(_ sender: UISlider) {
+ }
+
}
extension DebugLabelViewController: UIScrollViewDelegate {