From 4c220f8d54d080f4a53f7e0a3fae89fb37d6d530 Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Sun, 3 Nov 2019 23:14:07 +0000 Subject: [PATCH 1/2] Make colors for Quote and Pre elements optional. --- Aztec/Classes/TextKit/LayoutManager.swift | 24 +++++++++++++++-------- Aztec/Classes/TextKit/TextView.swift | 6 +++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Aztec/Classes/TextKit/LayoutManager.swift b/Aztec/Classes/TextKit/LayoutManager.swift index dbe233234..e9dac2c5e 100644 --- a/Aztec/Classes/TextKit/LayoutManager.swift +++ b/Aztec/Classes/TextKit/LayoutManager.swift @@ -9,15 +9,15 @@ class LayoutManager: NSLayoutManager { /// Blockquote's Left Border Color /// - var blockquoteBorderColor = UIColor(red: 0.52, green: 0.65, blue: 0.73, alpha: 1.0) + var blockquoteBorderColor: UIColor? = UIColor(red: 0.52, green: 0.65, blue: 0.73, alpha: 1.0) /// Blockquote's Background Color /// - var blockquoteBackgroundColor = UIColor(red: 0.91, green: 0.94, blue: 0.95, alpha: 1.0) + var blockquoteBackgroundColor: UIColor? = UIColor(red: 0.91, green: 0.94, blue: 0.95, alpha: 1.0) /// HTML Pre Background Color /// - var preBackgroundColor = UIColor(red: 243.0/255.0, green: 246.0/255.0, blue: 248.0/255.0, alpha: 1.0) + var preBackgroundColor: UIColor? = UIColor(red: 243.0/255.0, green: 246.0/255.0, blue: 248.0/255.0, alpha: 1.0) /// Closure that is expected to return the TypingAttributes associated to the Extra Line Fragment /// @@ -126,12 +126,17 @@ private extension LayoutManager { /// Draws a single Blockquote Line Fragment, in the specified Rectangle, using a given Graphics Context. /// private func drawBlockquote(in rect: CGRect, with context: CGContext) { - blockquoteBackgroundColor.setFill() - context.fill(rect) + if let blockquoteBackgroundColor = blockquoteBackgroundColor { + blockquoteBackgroundColor.setFill() + context.fill(rect) + + } - let borderRect = CGRect(origin: rect.origin, size: CGSize(width: blockquoteBorderWidth, height: rect.height)) - blockquoteBorderColor.setFill() - context.fill(borderRect) + if let blockquoteBorderColor = blockquoteBorderColor { + let borderRect = CGRect(origin: rect.origin, size: CGSize(width: blockquoteBorderWidth, height: rect.height)) + blockquoteBorderColor.setFill() + context.fill(borderRect) + } } } @@ -172,6 +177,9 @@ private extension LayoutManager { /// Draws a single HTML Pre Line Fragment, in the specified Rectangle, using a given Graphics Context. /// private func drawHTMLPre(in rect: CGRect, with context: CGContext) { + guard let preBackgroundColor = preBackgroundColor else { + return + } preBackgroundColor.setFill() context.fill(rect) } diff --git a/Aztec/Classes/TextKit/TextView.swift b/Aztec/Classes/TextKit/TextView.swift index 91cbcd72e..d4b3d3a92 100644 --- a/Aztec/Classes/TextKit/TextView.swift +++ b/Aztec/Classes/TextKit/TextView.swift @@ -275,7 +275,7 @@ open class TextView: UITextView { /// Blockquote Blocks Border Color. /// - @objc dynamic public var blockquoteBorderColor: UIColor { + @objc dynamic public var blockquoteBorderColor: UIColor? { get { return layout.blockquoteBorderColor } @@ -286,7 +286,7 @@ open class TextView: UITextView { /// Blockquote Blocks Background Color. /// - @objc dynamic public var blockquoteBackgroundColor: UIColor { + @objc dynamic public var blockquoteBackgroundColor: UIColor? { get { return layout.blockquoteBackgroundColor } @@ -309,7 +309,7 @@ open class TextView: UITextView { /// Pre Blocks Background Color. /// - @objc dynamic public var preBackgroundColor: UIColor { + @objc dynamic public var preBackgroundColor: UIColor? { get { return layout.preBackgroundColor } From e490a2251dfe53c3e4951caa2ed415efb709e04f Mon Sep 17 00:00:00 2001 From: Sergio Estevao Date: Sun, 3 Nov 2019 23:21:30 +0000 Subject: [PATCH 2/2] Improve colors used in demo for pre and quote formats. --- Example/Example/EditorDemoController.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Example/Example/EditorDemoController.swift b/Example/Example/EditorDemoController.swift index 9de85fff2..f46617af7 100644 --- a/Example/Example/EditorDemoController.swift +++ b/Example/Example/EditorDemoController.swift @@ -177,8 +177,9 @@ class EditorDemoController: UIViewController { titleTextView.textColor = UIColor.label editorView.htmlTextView.textColor = UIColor.label editorView.richTextView.textColor = UIColor.label - editorView.richTextView.blockquoteBackgroundColor = UIColor.tertiarySystemBackground - editorView.richTextView.preBackgroundColor = UIColor.tertiarySystemBackground + editorView.richTextView.blockquoteBackgroundColor = UIColor.secondarySystemBackground + editorView.richTextView.preBackgroundColor = UIColor.secondarySystemBackground + editorView.richTextView.blockquoteBorderColor = UIColor.secondarySystemFill var attributes = editorView.richTextView.linkTextAttributes attributes?[.foregroundColor] = UIColor.link } else {