Moved hasAttachmentImage to a function.
This commit is contained in:
parent
38912a4f85
commit
62418f5132
@ -19,9 +19,6 @@ public typealias ActionBlock = () -> ()
|
||||
|
||||
public var makeWholeViewClickable = false
|
||||
|
||||
/// Indication that attributed text attachment will affect range location of attributed text.
|
||||
public var hasAttachmentImageInsideText = false
|
||||
|
||||
/// Set this property if you want updateView to update the font based on this standard and the size passed in.
|
||||
public var standardFontSize: CGFloat = 0.0
|
||||
|
||||
@ -249,6 +246,7 @@ public typealias ActionBlock = () -> ()
|
||||
case "strikethrough":
|
||||
attributedString.addAttribute(.strikethroughStyle, value: NSUnderlineStyle.thick.rawValue, range: range)
|
||||
attributedString.addAttribute(.baselineOffset, value: 0, range: range)
|
||||
|
||||
case "color":
|
||||
if let colorHex = attribute.optionalStringForKey(KeyTextColor), !colorHex.isEmpty {
|
||||
attributedString.removeAttribute(.foregroundColor, range: range)
|
||||
@ -267,23 +265,9 @@ public typealias ActionBlock = () -> ()
|
||||
}
|
||||
|
||||
let mutableString = NSMutableAttributedString()
|
||||
let space = NSAttributedString(string: " ")
|
||||
let attachment = NSAttributedString(attachment: imageAttachment)
|
||||
|
||||
if location == 0 {
|
||||
mutableString.append(attachment)
|
||||
mutableString.append(space)
|
||||
} else {
|
||||
mutableString.append(space)
|
||||
mutableString.append(attachment)
|
||||
}
|
||||
|
||||
mutableString.append(NSAttributedString(attachment: imageAttachment))
|
||||
attributedString.insert(mutableString, at: location)
|
||||
|
||||
if location < attributedString.length {
|
||||
(label as? Label)?.hasAttachmentImageInsideText = true
|
||||
}
|
||||
|
||||
case "font":
|
||||
if let fontStyle = attribute.optionalStringForKey("style") {
|
||||
let styles = MFStyler.styleGetAttributedString("0", withStyle: fontStyle)
|
||||
@ -415,8 +399,8 @@ public typealias ActionBlock = () -> ()
|
||||
}
|
||||
|
||||
/**
|
||||
Appends an external link image to the end of the attributed string.
|
||||
Will provide one whitespace to the left of the icon
|
||||
Appends an external link image to the end of the attributed string.
|
||||
Will provide one whitespace to the left of the icon
|
||||
*/
|
||||
@objc public func appendExternalLinkIcon() {
|
||||
|
||||
@ -433,7 +417,7 @@ public typealias ActionBlock = () -> ()
|
||||
Insert external link icon anywhere within text of Label.
|
||||
|
||||
- Note: Each icon insertion adds 2 additional characters to the overall text length.
|
||||
This means that you MUST insert icons and links in the order they would appear.
|
||||
This means that you MUST insert icons and links in the order they would appear.
|
||||
- parameter index: Location within the associated text to insert an external Link Icon
|
||||
*/
|
||||
public func insertExternalLinkIcon(at index: Int) {
|
||||
@ -473,9 +457,9 @@ public typealias ActionBlock = () -> ()
|
||||
|
||||
DispatchQueue.global(qos: .default).async {
|
||||
|
||||
guard let url = URL(string: url),
|
||||
let data = try? Data(contentsOf: url)
|
||||
else { return }
|
||||
guard let url = URL(string: url),
|
||||
let data = try? Data(contentsOf: url)
|
||||
else { return }
|
||||
|
||||
imageAttachment.image = UIImage(data: data)
|
||||
DispatchQueue.main.sync {
|
||||
@ -485,6 +469,23 @@ public typealias ActionBlock = () -> ()
|
||||
|
||||
return imageAttachment
|
||||
}
|
||||
|
||||
/// Call to detect in the attributedText contains an NSTextAttachment.
|
||||
func textContainsTextAttachment() -> Bool {
|
||||
|
||||
guard let attributedText = attributedText else { return false }
|
||||
|
||||
var containsAttachment = false
|
||||
|
||||
attributedText.enumerateAttribute(.attachment, in: NSRange(location: 0, length: attributedText.length), options: []) { value, range, stop in
|
||||
if value is NSTextAttachment {
|
||||
containsAttachment = true
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return containsAttachment
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Atomization
|
||||
@ -495,7 +496,6 @@ extension Label {
|
||||
attributedText = nil
|
||||
textAlignment = .left
|
||||
originalAttributedString = nil
|
||||
hasAttachmentImageInsideText = false
|
||||
styleB2(true)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user