美文网首页iOS
iOS Range to frame

iOS Range to frame

作者: NieFeng1024 | 来源:发表于2017-04-26 20:42 被阅读39次

    pragma mark Private ------------ Range to frame

    - (CGRect)frameOfTextRange:(NSRange)range inTextView:(UITextView *)textView {
        UITextPosition *beginning = textView.beginningOfDocument;
        UITextPosition *start = [textView positionFromPosition:beginning offset:range.location];
        UITextPosition *end = [textView positionFromPosition:start offset:range.length];
        UITextRange *textRange = [textView textRangeFromPosition:start toPosition:end];
        CGRect rect = [textView firstRectForRange:textRange];
        return [textView convertRect:rect fromView:textView.textInputView];
    }
    

    相关文章

      网友评论

      本文标题:iOS Range to frame

      本文链接:https://www.haomeiwen.com/subject/pxywzttx.html