iOS 在UITextView中查找某个Range所在的Rect

 

 

代码如下(Swift 4):

 

extension UITextView {
    
    /// 查找文本范围所在的矩形范围
    ///
    /// - Parameter range: 文本范围
    /// - Returns: 文本范围所在的矩形范围
    func rect(forStringRange range: NSRange) -> CGRect? {
        
        guard let start = self.position(from: self.beginningOfDocument, offset: range.location) else { return nil }
        guard let end = self.position(from: start, offset: range.length) else { return nil }
        guard let textRange = self.textRange(from: start, to: end) else { return nil }
        let rect = self.firstRect(for: textRange)
        return self.convert(rect, from: self.textInputView)
    }
    
}

 

iOS 在UITextView中查找某个Range所在的Rect

上一篇:Django开发social-auth-app-django 第三方登陆-魏泯


下一篇:automapper 自动映射 集成asp.net Core2.1