refacgtorerd.
This commit is contained in:
parent
11b2ddc4dd
commit
73ac4b932b
@ -506,14 +506,17 @@ public typealias ActionBlock = () -> ()
|
|||||||
clauses.append(ActionableClause(range: range, actionBlock: actionBlock, accessibilityID: accessibleAction?.hash ?? -1))
|
clauses.append(ActionableClause(range: range, actionBlock: actionBlock, accessibilityID: accessibleAction?.hash ?? -1))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Provides a text container in memory of how the text would appear on screen.
|
/**
|
||||||
func abstractTextContainer() -> NSTextContainer? {
|
Provides a text container and layout manager of how the text would appear on screen.
|
||||||
|
They are used in tandem to derive low-level TextKit results of the label.
|
||||||
|
*/
|
||||||
|
public func abstractTextContainer() -> (NSTextContainer, NSLayoutManager)? {
|
||||||
|
|
||||||
// Must configure the attributed string to translate what would appear on screen to accurately analyze.
|
// Must configure the attributed string to translate what would appear on screen to accurately analyze.
|
||||||
guard let attributedText = attributedText else { return nil }
|
guard let attributedText = attributedText else { return nil }
|
||||||
|
|
||||||
let paragraph = NSMutableParagraphStyle()
|
let paragraph = NSMutableParagraphStyle()
|
||||||
paragraph.alignment = label.textAlignment
|
paragraph.alignment = textAlignment
|
||||||
|
|
||||||
let stagedAttributedString = NSMutableAttributedString(attributedString: attributedText)
|
let stagedAttributedString = NSMutableAttributedString(attributedString: attributedText)
|
||||||
stagedAttributedString.addAttributes([NSAttributedString.Key.paragraphStyle: paragraph], range: NSRange(location: 0, length: attributedText.string.count))
|
stagedAttributedString.addAttributes([NSAttributedString.Key.paragraphStyle: paragraph], range: NSRange(location: 0, length: attributedText.string.count))
|
||||||
@ -530,12 +533,14 @@ public typealias ActionBlock = () -> ()
|
|||||||
textContainer.maximumNumberOfLines = numberOfLines
|
textContainer.maximumNumberOfLines = numberOfLines
|
||||||
textContainer.size = bounds.size
|
textContainer.size = bounds.size
|
||||||
|
|
||||||
return textContainer
|
return (textContainer, layoutManager)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func boundingRect(forCharacterRange range: NSRange, in label: Label) -> CGRect {
|
public static func boundingRect(forCharacterRange range: NSRange, in label: Label) -> CGRect {
|
||||||
|
|
||||||
let textContainer = abstractTextContainer()
|
guard let abstractContainer = label.abstractTextContainer() else { return CGRect() }
|
||||||
|
let textContainer = abstractContainer.0
|
||||||
|
let layoutManager = abstractContainer.1
|
||||||
|
|
||||||
var glyphRange = NSRange()
|
var glyphRange = NSRange()
|
||||||
|
|
||||||
@ -678,7 +683,9 @@ extension UITapGestureRecognizer {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let textContainer = label.abstractTextContainer() else { return false }
|
guard let abstractContainer = label.abstractTextContainer() else { return false }
|
||||||
|
let textContainer = abstractContainer.0
|
||||||
|
let layoutManager = abstractContainer.1
|
||||||
|
|
||||||
let indexOfGlyph = layoutManager.glyphIndex(for: location(in: label), in: textContainer)
|
let indexOfGlyph = layoutManager.glyphIndex(for: location(in: label), in: textContainer)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user