diff --git a/Sources/UIExtensions/ZNSTextAttachmentLabel.swift b/Sources/UIExtensions/ZNSTextAttachmentLabel.swift index 5cc22b5..227c0e9 100644 --- a/Sources/UIExtensions/ZNSTextAttachmentLabel.swift +++ b/Sources/UIExtensions/ZNSTextAttachmentLabel.swift @@ -13,7 +13,7 @@ public class ZNSTextAttachmentLabel: UILabel { public override var attributedText: NSAttributedString? { didSet { attributedText?.enumerateAttribute(NSAttributedString.Key.attachment, in: NSMakeRange(0, attributedText?.string.utf16.count ?? 0), options: []) { (value, effectiveRange, nil) in - guard let attachment = value as? ZNSTextAttachmentPlaceholder else { + guard let attachment = value as? ZNSTextAttachment else { return } diff --git a/Sources/ZNSTextAttachment/ZNSTextAttachmentDataSource.swift b/Sources/ZNSTextAttachment/ZNSTextAttachmentDataSource.swift new file mode 100644 index 0000000..3320196 --- /dev/null +++ b/Sources/ZNSTextAttachment/ZNSTextAttachmentDataSource.swift @@ -0,0 +1,12 @@ +// +// ZNSTextAttachmentDataSource.swift +// +// +// Created by zhgchgli on 2023/3/5. +// + +import Foundation + +public protocol ZNSTextAttachmentDataSource: AnyObject { + func zNSTextAttachment(_ textAttachment: ZNSTextAttachment, loadImageURL imageURL: URL, completion: @escaping (Data) -> Void) +} diff --git a/Sources/ZNSTextAttachment/ZNSTextAttachmentDelegate.swift b/Sources/ZNSTextAttachment/ZNSTextAttachmentDelegate.swift new file mode 100644 index 0000000..ba260ca --- /dev/null +++ b/Sources/ZNSTextAttachment/ZNSTextAttachmentDelegate.swift @@ -0,0 +1,12 @@ +// +// ZNSTextAttachmentDelegate.swift +// +// +// Created by zhgchgli on 2023/3/5. +// + +import Foundation + +public protocol ZNSTextAttachmentDelegate: AnyObject { + func zNSTextAttachment(didLoad textAttachment: ZNSTextAttachment) +} diff --git a/Sources/ZNSTextAttachment/ZNSTextAttachmentHandler.swift b/Sources/ZNSTextAttachment/ZNSTextAttachmentHandler.swift new file mode 100644 index 0000000..e27f7da --- /dev/null +++ b/Sources/ZNSTextAttachment/ZNSTextAttachmentHandler.swift @@ -0,0 +1,10 @@ +// +// ZNSTextAttachmentHandler.swift +// +// +// Created by zhgchgli on 2023/3/5. +// + +import Foundation + +public typealias ZNSTextAttachmentHandler = (ZNSTextAttachmentDataSource & ZNSTextAttachmentDelegate) diff --git a/Sources/ZNSTextAttachment/ZNSTextAttachment.swift b/Sources/ZNSTextAttachment/iOS/ZNSTextAttachment.swift similarity index 72% rename from Sources/ZNSTextAttachment/ZNSTextAttachment.swift rename to Sources/ZNSTextAttachment/iOS/ZNSTextAttachment.swift index fe7285b..d611644 100644 --- a/Sources/ZNSTextAttachment/ZNSTextAttachment.swift +++ b/Sources/ZNSTextAttachment/iOS/ZNSTextAttachment.swift @@ -11,62 +11,25 @@ import UIKit import MobileCoreServices import UniformTypeIdentifiers -public protocol ZNSTextAttachmentDataSource: AnyObject { - func zNSTextAttachment(_ textAttachment: ZNSTextAttachmentPlaceholder, loadImageURL imageURL: URL, completion: @escaping (Data) -> Void) -} - -public protocol ZNSTextAttachmentDelegate: AnyObject { - func zNSTextAttachment(didLoad textAttachment: ZNSTextAttachmentPlaceholder) -} public class ZNSTextAttachment: NSTextAttachment { - - public let imageSize: CGSize? - - @available(iOS 13.0, *) - public init(image: UIImage) { - imageSize = image.size - super.init(image: image) - } - - public init(imageSize: CGSize?, data: Data, type: String) { - self.imageSize = imageSize - - super.init(data: data, ofType: type) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - public override func attachmentBounds(for textContainer: NSTextContainer?, proposedLineFragment lineFrag: CGRect, glyphPosition position: CGPoint, characterIndex charIndex: Int) -> CGRect { - - guard let imageWidth = imageSize?.width, - let imageHeight = imageSize?.height else { - return .zero - } - - let maxWidth = lineFrag.size.width - ((textContainer?.lineFragmentPadding ?? 0) * 2) - let factor = maxWidth / imageWidth - - return CGRect(origin: CGPoint.zero, size:CGSize(width: Int(imageWidth * factor), height: Int(imageHeight * factor))) - } -} - -public class ZNSTextAttachmentPlaceholder: NSTextAttachment { public let imageURL: URL public weak var delegate: ZNSTextAttachmentDelegate? public weak var dataSource: ZNSTextAttachmentDataSource? private let origin: CGPoint? + private let imageWidth: CGFloat? + private let imageHeight: CGFloat? private var isLoading: Bool = false private var textStorages: [WeakNSTextStorage] = [] private var labels: [WeakUILabel] = [] - public init(imageURL: URL, placeholderImage: UIImage? = nil, placeholderImageOrigin: CGPoint? = nil) { + public init(imageURL: URL, imageWidth: CGFloat? = nil, imageHeight: CGFloat? = nil, placeholderImage: UIImage? = nil, placeholderImageOrigin: CGPoint? = nil) { self.imageURL = imageURL + self.imageWidth = imageWidth + self.imageHeight = imageHeight self.origin = placeholderImageOrigin if let placeholderImageData = placeholderImage?.pngData() { @@ -122,14 +85,14 @@ public class ZNSTextAttachmentPlaceholder: NSTextAttachment { self.textStorages.forEach { value in value.rangesForAttachment(attachment: self)?.forEach({ range in value.textStorage?.deleteCharacters(in: range) - value.textStorage?.insert(NSAttributedString(attachment: ZNSTextAttachment(imageSize: image?.size, data: data, type: fileType)), at: range.location) + value.textStorage?.insert(NSAttributedString(attachment: ZResizableNSTextAttachment(imageSize: image?.size, fixedWidth: self.imageWidth, fixedHeight: self.imageHeight, data: data, type: fileType)), at: range.location) }) } self.labels.forEach { value in value.rangesForAttachment(attachment: self)?.forEach({ range in let attributedText = NSMutableAttributedString(attributedString: value.label?.attributedText ?? NSAttributedString()) attributedText.deleteCharacters(in: range) - attributedText.insert(NSAttributedString(attachment: ZNSTextAttachment(imageSize: image?.size, data: data, type: fileType)), at: range.location) + attributedText.insert(NSAttributedString(attachment: ZResizableNSTextAttachment(imageSize: image?.size, fixedWidth: self.imageWidth, fixedHeight: self.imageHeight, data: data, type: fileType)), at: range.location) value.label?.attributedText = attributedText }) } @@ -157,7 +120,7 @@ public class ZNSTextAttachmentPlaceholder: NSTextAttachment { } } -private extension ZNSTextAttachmentPlaceholder { +private extension ZNSTextAttachment { class WeakNSTextStorage { weak var textStorage: NSTextStorage? @@ -166,7 +129,7 @@ private extension ZNSTextAttachmentPlaceholder { self.textStorage = textStorage } - func rangesForAttachment(attachment: ZNSTextAttachmentPlaceholder) -> [NSRange]? { + func rangesForAttachment(attachment: ZNSTextAttachment) -> [NSRange]? { guard let attributedString = textStorage else { return nil } @@ -174,7 +137,7 @@ private extension ZNSTextAttachmentPlaceholder { var ranges = [NSRange]() attributedString.enumerateAttribute(NSAttributedString.Key.attachment, in: range, options: []) { (value, effectiveRange, nil) in - guard (value as? ZNSTextAttachmentPlaceholder) == attachment else { + guard (value as? ZNSTextAttachment) == attachment else { return } ranges.append(effectiveRange) @@ -196,7 +159,7 @@ private extension ZNSTextAttachmentPlaceholder { } } -private extension ZNSTextAttachmentPlaceholder { +private extension ZNSTextAttachment { class WeakUILabel { weak var label: UILabel? @@ -205,7 +168,7 @@ private extension ZNSTextAttachmentPlaceholder { self.label = label } - func rangesForAttachment(attachment: ZNSTextAttachmentPlaceholder) -> [NSRange]? { + func rangesForAttachment(attachment: ZNSTextAttachment) -> [NSRange]? { guard let attributedString = label?.attributedText else { return nil } @@ -213,7 +176,7 @@ private extension ZNSTextAttachmentPlaceholder { var ranges = [NSRange]() attributedString.enumerateAttribute(NSAttributedString.Key.attachment, in: range, options: []) { (value, effectiveRange, nil) in - guard (value as? ZNSTextAttachmentPlaceholder) == attachment else { + guard (value as? ZNSTextAttachment) == attachment else { return } ranges.append(effectiveRange) diff --git a/Sources/ZNSTextAttachment/iOS/ZResizableNSTextAttachment.swift b/Sources/ZNSTextAttachment/iOS/ZResizableNSTextAttachment.swift new file mode 100644 index 0000000..3be5fe5 --- /dev/null +++ b/Sources/ZNSTextAttachment/iOS/ZResizableNSTextAttachment.swift @@ -0,0 +1,57 @@ +// +// ZResizableNSTextAttachment.swift +// +// +// Created by zhgchgli on 2023/3/5. +// + +import Foundation + +#if canImport(UIKit) +import UIKit + +public class ZResizableNSTextAttachment: NSTextAttachment { + + public let imageSize: CGSize? + public let fixedWidth: CGFloat? + public let fixedHeight: CGFloat? + + public init(imageSize: CGSize?, fixedWidth: CGFloat?, fixedHeight: CGFloat?, data: Data, type: String) { + self.imageSize = imageSize + self.fixedWidth = fixedWidth + self.fixedHeight = fixedHeight + + super.init(data: data, ofType: type) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + public override func attachmentBounds(for textContainer: NSTextContainer?, proposedLineFragment lineFrag: CGRect, glyphPosition position: CGPoint, characterIndex charIndex: Int) -> CGRect { + + if let fixedWidth = self.fixedWidth, + let fixedHeight = self.fixedHeight { + return CGRect(origin: .zero, size: CGSize(width: fixedWidth, height: fixedHeight)) + } + + guard let imageWidth = imageSize?.width, + let imageHeight = imageSize?.height else { + return .zero + } + + if let fixedWidth = self.fixedWidth { + let factor = fixedWidth / imageWidth + return CGRect(origin: .zero, size:CGSize(width: Int(fixedWidth), height: Int(imageHeight * factor))) + } else if let fixedHeight = self.fixedHeight { + let factor = fixedHeight / imageHeight + return CGRect(origin: .zero, size:CGSize(width: Int(imageWidth * factor), height: Int(fixedHeight))) + } else { + let maxWidth = lineFrag.size.width - ((textContainer?.lineFragmentPadding ?? 0) * 2) + let factor = maxWidth / imageWidth + + return CGRect(origin: .zero, size:CGSize(width: Int(imageWidth * factor), height: Int(imageHeight * factor))) + } + } +} +#endif diff --git a/Sources/ZNSTextAttachment/ZNSTextAttachmentForMacOS.swift b/Sources/ZNSTextAttachment/macOS/ZNSTextAttachmentForMacOS.swift similarity index 69% rename from Sources/ZNSTextAttachment/ZNSTextAttachmentForMacOS.swift rename to Sources/ZNSTextAttachment/macOS/ZNSTextAttachmentForMacOS.swift index 3575dfd..e3c1dc6 100644 --- a/Sources/ZNSTextAttachment/ZNSTextAttachmentForMacOS.swift +++ b/Sources/ZNSTextAttachment/macOS/ZNSTextAttachmentForMacOS.swift @@ -1,64 +1,32 @@ + +// +// ZNSTextAttachmentLabel.swift // -// ZNSTextAttachmentForMacOS.swift -// // -// Created by zhgchgli on 2023/3/5. +// Created by https://zhgchg.li on 2023/3/5. // -import Foundation #if canImport(AppKit) import AppKit import UniformTypeIdentifiers -public protocol ZNSTextAttachmentDataSource: AnyObject { - func zNSTextAttachment(_ textAttachment: ZNSTextAttachmentPlaceholder, loadImageURL imageURL: URL, completion: @escaping (Data) -> Void) -} - -public protocol ZNSTextAttachmentDelegate: AnyObject { - func zNSTextAttachment(didLoad textAttachment: ZNSTextAttachmentPlaceholder) -} - public class ZNSTextAttachment: NSTextAttachment { - - public let imageSize: CGSize? - - public init(imageSize: CGSize?, data: Data, type: String) { - self.imageSize = imageSize - - super.init(data: data, ofType: type) - } - - required init?(coder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - public override func attachmentBounds(for textContainer: NSTextContainer?, proposedLineFragment lineFrag: CGRect, glyphPosition position: CGPoint, characterIndex charIndex: Int) -> CGRect { - - guard let imageWidth = imageSize?.width, - let imageHeight = imageSize?.height else { - return .zero - } - - let maxWidth = lineFrag.size.width - ((textContainer?.lineFragmentPadding ?? 0) * 2) - let factor = maxWidth / imageWidth - - return CGRect(origin: CGPoint.zero, size:CGSize(width: Int(imageWidth * factor), height: Int(imageHeight * factor))) - } -} - -public class ZNSTextAttachmentPlaceholder: NSTextAttachment { public let imageURL: URL public weak var delegate: ZNSTextAttachmentDelegate? public weak var dataSource: ZNSTextAttachmentDataSource? private let origin: CGPoint? + private let imageWidth: CGFloat? + private let imageHeight: CGFloat? private var isLoading: Bool = false private var textStorages: [WeakNSTextStorage] = [] - public init(imageURL: URL, placeholderImage: NSImage? = nil, placeholderImageOrigin: CGPoint? = nil) { + public init(imageURL: URL, imageWidth: CGFloat? = nil, imageHeight: CGFloat? = nil, placeholderImage: NSImage? = nil, placeholderImageOrigin: CGPoint? = nil) { self.imageURL = imageURL + self.imageWidth = imageWidth + self.imageHeight = imageHeight self.origin = placeholderImageOrigin if let placeholderImageData = placeholderImage?.tiffRepresentation { @@ -110,7 +78,7 @@ public class ZNSTextAttachmentPlaceholder: NSTextAttachment { self.textStorages.forEach { value in value.rangesForAttachment(attachment: self)?.forEach({ range in value.textStorage?.deleteCharacters(in: range) - value.textStorage?.insert(NSAttributedString(attachment: ZNSTextAttachment(imageSize: image?.size, data: data, type: fileType)), at: range.location) + value.textStorage?.insert(NSAttributedString(attachment: ZResizableNSTextAttachment(imageSize: image?.size, fixedWidth: self.imageWidth, fixedHeight: self.imageHeight, data: data, type: fileType)), at: range.location) }) } self.delegate?.zNSTextAttachment(didLoad: self) @@ -137,7 +105,7 @@ public class ZNSTextAttachmentPlaceholder: NSTextAttachment { } } -private extension ZNSTextAttachmentPlaceholder { +private extension ZNSTextAttachment { class WeakNSTextStorage { weak var textStorage: NSTextStorage? @@ -146,7 +114,7 @@ private extension ZNSTextAttachmentPlaceholder { self.textStorage = textStorage } - func rangesForAttachment(attachment: ZNSTextAttachmentPlaceholder) -> [NSRange]? { + func rangesForAttachment(attachment: ZNSTextAttachment) -> [NSRange]? { guard let attributedString = textStorage else { return nil } @@ -154,7 +122,7 @@ private extension ZNSTextAttachmentPlaceholder { var ranges = [NSRange]() attributedString.enumerateAttribute(NSAttributedString.Key.attachment, in: range, options: []) { (value, effectiveRange, nil) in - guard (value as? ZNSTextAttachmentPlaceholder) == attachment else { + guard (value as? ZNSTextAttachment) == attachment else { return } ranges.append(effectiveRange) diff --git a/Sources/ZNSTextAttachment/macOS/ZResizableNSTextAttachmentForMacOS.swift b/Sources/ZNSTextAttachment/macOS/ZResizableNSTextAttachmentForMacOS.swift new file mode 100644 index 0000000..9022323 --- /dev/null +++ b/Sources/ZNSTextAttachment/macOS/ZResizableNSTextAttachmentForMacOS.swift @@ -0,0 +1,57 @@ +// +// ZResizableNSTextAttachment.swift +// +// +// Created by zhgchgli on 2023/3/5. +// + +import Foundation + +#if canImport(AppKit) +import AppKit + +public class ZResizableNSTextAttachment: NSTextAttachment { + + public let imageSize: CGSize? + public let fixedWidth: CGFloat? + public let fixedHeight: CGFloat? + + public init(imageSize: CGSize?, fixedWidth: CGFloat?, fixedHeight: CGFloat?, data: Data, type: String) { + self.imageSize = imageSize + self.fixedWidth = fixedWidth + self.fixedHeight = fixedHeight + + super.init(data: data, ofType: type) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + public override func attachmentBounds(for textContainer: NSTextContainer?, proposedLineFragment lineFrag: CGRect, glyphPosition position: CGPoint, characterIndex charIndex: Int) -> CGRect { + + if let fixedWidth = self.fixedWidth, + let fixedHeight = self.fixedHeight { + return CGRect(origin: .zero, size: CGSize(width: fixedWidth, height: fixedHeight)) + } + + guard let imageWidth = imageSize?.width, + let imageHeight = imageSize?.height else { + return .zero + } + + if let fixedWidth = self.fixedWidth { + let factor = fixedWidth / imageWidth + return CGRect(origin: .zero, size:CGSize(width: Int(fixedWidth), height: Int(imageHeight * factor))) + } else if let fixedHeight = self.fixedHeight { + let factor = fixedHeight / imageHeight + return CGRect(origin: .zero, size:CGSize(width: Int(imageWidth * factor), height: Int(fixedHeight))) + } else { + let maxWidth = lineFrag.size.width - ((textContainer?.lineFragmentPadding ?? 0) * 2) + let factor = maxWidth / imageWidth + + return CGRect(origin: .zero, size:CGSize(width: Int(imageWidth * factor), height: Int(imageHeight * factor))) + } + } +} +#endif diff --git a/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/MixedViewController.swift b/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/MixedViewController.swift index 9b8f88d..60f46ce 100644 --- a/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/MixedViewController.swift +++ b/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/MixedViewController.swift @@ -17,7 +17,7 @@ class MixedViewController: UIViewController { super.viewDidLoad() // Do any additional setup after loading the view. - let attachment = ZNSTextAttachmentPlaceholder(imageURL: URL(string: "https://zhgchg.li/assets/a5643de271e4/1*A0yXupXW9-F9ZWe4gp2ObA.jpeg")!, placeholderImage: UIImage(systemName: "viewfinder.circle.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal)) + let attachment = ZNSTextAttachment(imageURL: URL(string: "https://zhgchg.li/assets/a5643de271e4/1*A0yXupXW9-F9ZWe4gp2ObA.jpeg")!, imageWidth: 300, placeholderImage: UIImage(systemName: "viewfinder.circle.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal)) let data = TestData.generate(with: attachment) @@ -30,7 +30,7 @@ class MixedViewController: UIViewController { } extension MixedViewController: ZNSTextAttachmentDataSource { - func zNSTextAttachment(_ textAttachment: ZNSTextAttachmentPlaceholder, loadImageURL imageURL: URL, completion: @escaping (Data) -> Void) { + func zNSTextAttachment(_ textAttachment: ZNSTextAttachment, loadImageURL imageURL: URL, completion: @escaping (Data) -> Void) { let dataTask = URLSession.shared.dataTask(with: URL(string: imageURL.absoluteString+"?q=\(UUID().uuidString)")!) { (data, response, error) in guard let data = data, error == nil else { @@ -48,7 +48,7 @@ extension MixedViewController: ZNSTextAttachmentDataSource { extension MixedViewController: ZNSTextAttachmentDelegate { - func zNSTextAttachment(didLoad textAttachment: ZNSTextAttachmentPlaceholder) { + func zNSTextAttachment(didLoad textAttachment: ZNSTextAttachment) { // } } diff --git a/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/TestData.swift b/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/TestData.swift index 15f9820..a1482d3 100644 --- a/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/TestData.swift +++ b/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/TestData.swift @@ -9,7 +9,7 @@ import Foundation import ZNSTextAttachment struct TestData { - static func generate(with attachment: ZNSTextAttachmentPlaceholder) -> NSAttributedString { + static func generate(with attachment: ZNSTextAttachment) -> NSAttributedString { let attributedString = NSMutableAttributedString() attributedString.append(NSAttributedString(string: "- 使用純 Swift 開發,透過 Regex 剖析出 HTML Tag 並經過 Tokenization,分析修正 Tag 正確性(修正沒有 end 的 tag & 錯位 tag),再轉換成 abstract syntax tree,最終使用 Visitor Pattern 將 HTML Tag 與抽象樣式對應,得到最終 NSAttributedString 結果;其中不依賴任何 Parser Lib。\n")) attributedString.append(NSAttributedString(string: "- 支援 HTML Render (to NSAttributedString) / Stripper (剝離 HTML Tag) / Selector 功能\n")) diff --git a/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/UILabelsViewController.swift b/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/UILabelsViewController.swift index 8718061..8e0bb54 100644 --- a/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/UILabelsViewController.swift +++ b/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/UILabelsViewController.swift @@ -19,7 +19,7 @@ class UILabelsViewController: UIViewController { super.viewDidLoad() // Do any additional setup after loading the view. - let attachment = ZNSTextAttachmentPlaceholder(imageURL: URL(string: "https://zhgchg.li/assets/a5643de271e4/1*A0yXupXW9-F9ZWe4gp2ObA.jpeg")!, placeholderImage: UIImage(systemName: "viewfinder.circle.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal)) + let attachment = ZNSTextAttachment(imageURL: URL(string: "https://zhgchg.li/assets/a5643de271e4/1*A0yXupXW9-F9ZWe4gp2ObA.jpeg")!, placeholderImage: UIImage(systemName: "viewfinder.circle.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal)) let data = TestData.generate(with: attachment) @@ -35,7 +35,7 @@ class UILabelsViewController: UIViewController { } extension UILabelsViewController: ZNSTextAttachmentDataSource { - func zNSTextAttachment(_ textAttachment: ZNSTextAttachmentPlaceholder, loadImageURL imageURL: URL, completion: @escaping (Data) -> Void) { + func zNSTextAttachment(_ textAttachment: ZNSTextAttachment, loadImageURL imageURL: URL, completion: @escaping (Data) -> Void) { let dataTask = URLSession.shared.dataTask(with: URL(string: imageURL.absoluteString+"?q=\(UUID().uuidString)")!) { (data, response, error) in guard let data = data, error == nil else { @@ -53,7 +53,7 @@ extension UILabelsViewController: ZNSTextAttachmentDataSource { extension UILabelsViewController: ZNSTextAttachmentDelegate { - func zNSTextAttachment(didLoad textAttachment: ZNSTextAttachmentPlaceholder) { + func zNSTextAttachment(didLoad textAttachment: ZNSTextAttachment) { // } } diff --git a/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/UITextViewsViewController.swift b/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/UITextViewsViewController.swift index ba1c2b9..391fadf 100644 --- a/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/UITextViewsViewController.swift +++ b/ZNSTextAttachment-Demo/ZNSTextAttachment-Demo/UITextViewsViewController.swift @@ -20,7 +20,7 @@ class UITextViewsViewController: UIViewController { super.viewDidLoad() // Do any additional setup after loading the view. - let attachment = ZNSTextAttachmentPlaceholder(imageURL: URL(string: "https://zhgchg.li/assets/a5643de271e4/1*A0yXupXW9-F9ZWe4gp2ObA.jpeg")!, placeholderImage: UIImage(systemName: "viewfinder.circle.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal)) + let attachment = ZNSTextAttachment(imageURL: URL(string: "https://zhgchg.li/assets/a5643de271e4/1*A0yXupXW9-F9ZWe4gp2ObA.jpeg")!, placeholderImage: UIImage(systemName: "viewfinder.circle.fill")?.withTintColor(.red, renderingMode: .alwaysOriginal)) let data = TestData.generate(with: attachment) @@ -34,7 +34,7 @@ class UITextViewsViewController: UIViewController { } extension UITextViewsViewController: ZNSTextAttachmentDataSource { - func zNSTextAttachment(_ textAttachment: ZNSTextAttachmentPlaceholder, loadImageURL imageURL: URL, completion: @escaping (Data) -> Void) { + func zNSTextAttachment(_ textAttachment: ZNSTextAttachment, loadImageURL imageURL: URL, completion: @escaping (Data) -> Void) { let dataTask = URLSession.shared.dataTask(with: URL(string: imageURL.absoluteString+"?q=\(UUID().uuidString)")!) { (data, response, error) in guard let data = data, error == nil else { @@ -52,7 +52,7 @@ extension UITextViewsViewController: ZNSTextAttachmentDataSource { extension UITextViewsViewController: ZNSTextAttachmentDelegate { - func zNSTextAttachment(didLoad textAttachment: ZNSTextAttachmentPlaceholder) { + func zNSTextAttachment(didLoad textAttachment: ZNSTextAttachment) { } } diff --git a/scripts/ZNSTextAttachment.podspec b/scripts/ZNSTextAttachment.podspec index 4b154df..8fc58fe 100644 --- a/scripts/ZNSTextAttachment.podspec +++ b/scripts/ZNSTextAttachment.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "ZNSTextAttachment" - s.version = "1.0.0" - s.summary = "ZNSTextAttachment enables NSTextAttachment to download images from remote URLs, and supports both UITextView and UILabel for multiple attachments." + s.version = "1.0.1" + s.summary = "ZNSTextAttachment enables NSTextAttachment to download images from remote URLs." s.homepage = "https://github.com/ZhgChgLi/ZNSTextAttachment" s.license = { :type => "MIT", :file => "LICENSE" } s.author = { "ZhgChgLi" => "me@zhgchg.li" }