UITextView get the current line

后端 未结 3 1145
暖寄归人
暖寄归人 2021-02-09 03:44

Is there a way (crazy hacks welcome) to get the current line as a string of a UITextView? This would include word wrapping, etc. For example, in this case:

3条回答
  •  忘了有多久
    2021-02-09 04:20

    This worked for me (self = the UITextView)

    func getLineString() -> String {
        return (self.text! as NSString).substringWithRange((self.text! as NSString).lineRangeForRange(self.selectedRange))
    }
    

提交回复
热议问题