1
0
mirror of https://github.com/metabolist/metatext synced 2025-01-22 23:41:38 +01:00
metatext-app-ios-iphone-ipad/Views/UIKit/AnimatedTextAttachment.swift
2021-02-22 16:35:56 -08:00

27 lines
915 B
Swift

// Copyright © 2021 Metabolist. All rights reserved.
import SDWebImage
import UIKit
final class AnimatedTextAttachment: NSTextAttachment {
var imageURL: URL?
var imageView = SDAnimatedImageView()
var imageBounds: CGRect?
override func image(forBounds imageBounds: CGRect,
textContainer: NSTextContainer?,
characterIndex charIndex: Int) -> UIImage? {
if let textContainer = textContainer,
let textContainerImageBounds = textContainer.layoutManager?.boundingRect(
forGlyphRange: NSRange(location: charIndex, length: 1),
in: textContainer),
textContainerImageBounds != .zero {
self.imageBounds = textContainerImageBounds
} else {
self.imageBounds = imageBounds
}
return nil // rendered by AnimatingLayoutManager or AnimatedAttachmentLabel
}
}