2016-11-28 78 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 
}