有用的 TextKit 2 辅助工具集合。

用于构建 STTextView 的 TextKit 2 辅助工具集合。

用法

NSRange 扩展

NSRange.notFound
NSRange.isEmpty
NSRange.nsValue

NSRange(_ textRange: NSTextRange, in textContentManager: NSTextContentManager)
NSRange(_ textLocation: NSTextLocation, in textContentManager: NSTextContentManager)

NSTextRange 扩展

NSTextRange(_ nsRange: NSRange, in textContentManager: NSTextContentManager)

func length(in textContentManager: NSTextContentManager) -> Int
func clamped(to textRange: NSTextRange) -> NSTextRange?

NSTextContentManager 扩展

func location(at offset: Int) -> NSTextLocation?
func location(line lineIdx: Int, character characterIdx: Int? = 0) -> NSTextLocation?

func position(_ location: NSTextLocation) -> (row: Int, column: Int)?

func attributedString(in range: NSTextRange?) -> NSAttributedString?

NSTextLayoutManager 扩展

func textLineFragment(at location: NSTextLocation) -> NSTextLineFragment?
func textLineFragment(at point: CGPoint) -> NSTextLineFragment?

func extraLineTextLayoutFragment() -> NSTextLayoutFragment?
func extraLineTextLineFragment() -> NSTextLineFragment?

func location(interactingAt point: CGPoint, inContainerAt containerLocation: NSTextLocation) -> NSTextLocation?

func textSegmentFrame(at location: NSTextLocation, type: NSTextLayoutManager.SegmentType, options: SegmentOptions = [.upstreamAffinity]) -> CGRect?
func textSegmentFrame(in textRange: NSTextRange, type: NSTextLayoutManager.SegmentType, options: SegmentOptions = [.upstreamAffinity, .rangeNotRequired]) -> CGRect?

func typographicBounds(in textRange: NSTextRange) -> CGRect?

func enumerateTextLayoutFragments(in range: NSTextRange, options: NSTextLayoutFragment.EnumerationOptions = [], using block: (NSTextLayoutFragment) -> Bool) -> NSTextLocation?

var insertionPointLocations: [NSTextLocation]
var insertionPointSelections: [NSTextSelection]

NSTextLayoutFragment 扩展

var isExtraLineFragment: Bool

func textLineFragment(at location: NSTextLocation, in textContentManager: NSTextContentManager? = nil) -> NSTextLineFragment?
func textLineFragment(at location: CGPoint, in textContentManager: NSTextContentManager? = nil) -> NSTextLineFragment?

NSTextLineFragment 扩展

textRange(in textLayoutFragment: NSTextLayoutFragment) -> NSTextRange?

var isExtraLineFragment: Bool

NSTextLocation 扩展

static func == (lhs: Self, rhs: Self) -> Bool
static func != (lhs: Self, rhs: Self) -> Bool
static func < (lhs: Self, rhs: Self) -> Bool
static func <= (lhs: Self, rhs: Self) -> Bool
static func > (lhs: Self, rhs: Self) -> Bool
static func >= (lhs: Self, rhs: Self) -> Bool
static func ~= (lhs: Self, rhs: Self) -> Bool

贡献与协作

非常期待听到您的声音!可以通过 issue 或 pull request 联系我。