Hello,
is this useable in B4I?
With this is it possible to count the lines of a textview. I need the line Count, because i set the view height per code if the linecount has changed.
My try was this, but i dont know what is wrong:
is this useable in B4I?
With this is it possible to count the lines of a textview. I need the line Count, because i set the view height per code if the linecount has changed.
My try was this, but i dont know what is wrong:
B4X:
Sub LineCount(view As Object) As Int
Dim NativeMe As NativeObject = Me
Return NativeMe.RunMethod("numberOfLines:", Array (view))
End Sub
#If ObjC
extension UITextView {
func numberOfLines() -> Int {
let layoutManager = self.layoutManager
let numberOfGlyphs = layoutManager.numberOfGlyphs
var lineRange: NSRange = NSMakeRange(0, 1)
var index = 0
var numberOfLines = 0
while index < numberOfGlyphs {
layoutManager.lineFragmentRectForGlyphAtIndex(
index, effectiveRange: &lineRange
)
index = NSMaxRange(lineRange)
numberOfLines += 1
}
return numberOfLines
}
}
#End If