Ios 如何计算NSLayoutManager中的图示符数
如何获取Ios 如何计算NSLayoutManager中的图示符数,ios,swift,glyph,nslayoutmanager,Ios,Swift,Glyph,Nslayoutmanager,如何获取NSLayoutManager中的glyph总数 我制作了一个光标图层,覆盖在自定义文本视图上,如下所示: func moveCursorToGlyphIndex(glyphIndex: Int) { // get bounding rect for glyph var rect = self.layoutManager.boundingRectForGlyphRange(NSRange(location: glyphIndex, length: 1), inTextC
NSLayoutManager
中的glyph总数
我制作了一个光标图层,覆盖在自定义文本视图上,如下所示:
func moveCursorToGlyphIndex(glyphIndex: Int) {
// get bounding rect for glyph
var rect = self.layoutManager.boundingRectForGlyphRange(NSRange(location: glyphIndex, length: 1), inTextContainer: view.textContainer)
rect.origin.y = self.textContainerInset.top
rect.size.width = cursorWidth
// set cursor layer frame to right edge of rect
cursorLayer.frame = rect
}
if glyphIndex < self.layoutManager.glyphCount { // doesn't work
// ...
}
然而,我想确保glyphIndex
不超出范围。大概是这样的:
func moveCursorToGlyphIndex(glyphIndex: Int) {
// get bounding rect for glyph
var rect = self.layoutManager.boundingRectForGlyphRange(NSRange(location: glyphIndex, length: 1), inTextContainer: view.textContainer)
rect.origin.y = self.textContainerInset.top
rect.size.width = cursorWidth
// set cursor layer frame to right edge of rect
cursorLayer.frame = rect
}
if glyphIndex < self.layoutManager.glyphCount { // doesn't work
// ...
}
如果glyphIndex
不过,我无法通过反复试验找到合适的房产,网上搜索也没有给出任何答案
我终于在文档中找到了它(现在看起来很明显),但因为它花费了很长时间,我决定在这里添加一个问答
layoutManager.numberOfGlyphs
这在文本布局编程指南文档中进行了演示