From e8ff383b821516349a63d9a62bbdccf76eeb70e3 Mon Sep 17 00:00:00 2001 From: Tony Loehr Date: Fri, 10 Jan 2020 10:51:02 -0800 Subject: [PATCH] Card part attributed text patch (#222) * added UITextView Card Part * Implementation of CardPartAttributesTextView * Implementation of CardPartAttributesTextView * Implementation of CardPartAttributesTextView with adjustments * Implementation of CardPartAttributesTextView with fixes * Implementation of CardPartAttributesTextView with README updates * patch of CardPartAttributedTextView * cleanup * fixed threading issue preventing font and textColor updating * wrapped didSet methods on main thread --- .../CardPartAttributedTextView.swift | 53 +++++++++++++------ 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/CardParts/src/Classes/Card Parts/CardPartAttributedTextView.swift b/CardParts/src/Classes/Card Parts/CardPartAttributedTextView.swift index 93846fa9..a9074018 100644 --- a/CardParts/src/Classes/Card Parts/CardPartAttributedTextView.swift +++ b/CardParts/src/Classes/Card Parts/CardPartAttributedTextView.swift @@ -68,73 +68,94 @@ public class CardPartAttributedTextView: UIView, CardPartView { /// use in cases of plain text public var text: String? { didSet { - textView.text = text + DispatchQueue.main.async { + self.textView.text = self.text + } } } /// use in cases of links or other public var attributedText: NSMutableAttributedString? { didSet { - textView.attributedText = attributedText + DispatchQueue.main.async { + self.textView.attributedText = self.attributedText + } } } /// set text font public var font: UIFont? { didSet { - textView.font = font + DispatchQueue.main.async { + self.textView.font = self.font + } } } /// set text color public var textColor: UIColor? { didSet { - textView.textColor = textColor + DispatchQueue.main.async { + self.textView.textColor = self.textColor + } } } /// set whether the text within a text field is editable public var isEditable: Bool { didSet { - textView.isEditable = isEditable + DispatchQueue.main.async { + self.textView.isEditable = self.isEditable + } } } /// use to specify data that should automatically be passed toother applications as URLs, e.g. phone numbers public var dataDetectorTypes: UIDataDetectorTypes { didSet { - textView.dataDetectorTypes = dataDetectorTypes + DispatchQueue.main.async { + self.textView.dataDetectorTypes = self.dataDetectorTypes + } } } /// use to specify text alignment wthin the text field public var textAlignment: NSTextAlignment { didSet { - textView.textAlignment = textAlignment + DispatchQueue.main.async { + self.textView.textAlignment = self.textAlignment + } } } /// set attributes of linked text public var linkTextAttributes: [NSAttributedString.Key : Any] { didSet { - textView.linkTextAttributes = linkTextAttributes + DispatchQueue.main.async { + self.textView.linkTextAttributes = self.linkTextAttributes + } } } /// allows for exclusion paths to be added for text wrapping public var exclusionPath: [UIBezierPath]? { didSet { - let imageFrame = updateExclusionPath() - let exclusionPath = UIBezierPath(rect: imageFrame) - self.textView.textContainer.exclusionPaths = [exclusionPath] + DispatchQueue.main.async { + let imageFrame = self.updateExclusionPath() + let exclusionPath = UIBezierPath(rect: imageFrame) + self.textView.textContainer.exclusionPaths = [exclusionPath] + } } } /// set line spacing public var lineSpacing: CGFloat = 1.0 { didSet { - let style = NSMutableParagraphStyle() - style.lineSpacing = lineSpacing - + DispatchQueue.main.async { + let style = NSMutableParagraphStyle() + style.lineSpacing = self.lineSpacing + } } } /// set line height public var lineHeightMultiple: CGFloat = 1.1 { didSet { - let style = NSMutableParagraphStyle() - style.lineHeightMultiple = lineHeightMultiple + DispatchQueue.main.async { + let style = NSMutableParagraphStyle() + style.lineHeightMultiple = self.lineHeightMultiple + } } }