2016-11-28 72 views
0

如何知道UITextView会因为空间不足而缩短文字?我知道我可以使用boundingRectWithSizesizeThatFit来计算,但UITextViewexclusionPaths会发生什么变化。我想要在多边形中放置字符串,并增加多边形的大小,直到字符串布局而不缩短。任何想法,如何获得布尔回报,目前的设置会缩短?UITextView将缩短文本?

self.tv.textContainer.exclusionPaths = myArrayOfBezierPaths; 
+0

[你看了吗?(http://stackoverflow.com/a/19917287/312312) – Lefteris

回答

2
func isSizeFitForTextView() -> Bool{ 
    let layoutManager = self.textView.layoutManager 
    let glyphIndex = layoutManager.glyphIndexForCharacter(at:(self.textView.text as NSString).length) 

    let range = layoutManager.truncatedGlyphRange(inLineFragmentForGlyphAt: glyphIndex) 

    return range.location != NSNotFound 
}