Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何计算NSLayoutManager中的图示符数_Ios_Swift_Glyph_Nslayoutmanager - Fatal编程技术网

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
这在文本布局编程指南文档中进行了演示