久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

從 NSRange 創(chuàng)建 UITextRange

Create UITextRange from NSRange(從 NSRange 創(chuàng)建 UITextRange)
本文介紹了從 NSRange 創(chuàng)建 UITextRange的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

我需要在文本視圖中找到不同范圍的像素幀.我正在使用 - (CGRect)firstRectForRange:(UITextRange *)range; 來做到這一點(diǎn).但是我不知道如何實(shí)際創(chuàng)建 UITextRange.

I need to find the pixel-frame for different ranges in a textview. I'm using the - (CGRect)firstRectForRange:(UITextRange *)range; to do it. However I can't find out how to actually create a UITextRange.

基本上這就是我要找的東西:

Basically this is what I'm looking for:

- (CGRect)frameOfTextRange:(NSRange)range inTextView:(UITextView *)textView {

    UITextRange*range2 = [UITextRange rangeWithNSRange:range]; //DOES NOT EXIST 
    CGRect rect = [textView firstRectForRange:range2];
    return rect;
}

Apple 說必須繼承 UITextRangeUITextPosition 才能采用 UITextInput 協(xié)議.我不這樣做,但我還是嘗試了,按照文檔的示例代碼并將子類傳遞給 firstRectForRange 導(dǎo)致崩潰.

Apple says one has to subclass UITextRange and UITextPosition in order to adopt the UITextInput protocol. I don't do that, but I tried anyway, following the doc's example code and passing the subclass to firstRectForRange which resulted in crashing.

如果有更簡(jiǎn)單的方法可以將不同顏色的 UILables 添加到 textview,請(qǐng)告訴我.我曾嘗試使用 UIWebView 并將 content editable 設(shè)置為 TRUE,但我不喜歡與 JS 交流,而著色是我唯一需要的.

If there is a easier way of adding different colored UILables to a textview, please tell me. I have tried using UIWebView with content editable set to TRUE, but I'm not fond of communicating with JS, and coloring is the only thing I need.

提前致謝.

推薦答案

您可以使用 textRangeFromPosition:toPosition 方法創(chuàng)建文本范圍.此方法需要兩個(gè)位置,因此您需要計(jì)算范圍開始和結(jié)束的位置.這是通過 positionFromPosition:offset 方法完成的,該方法從另一個(gè)位置返回一個(gè)位置和一個(gè)字符偏移量.

You can create a text range with the method textRangeFromPosition:toPosition. This method requires two positions, so you need to compute the positions for the start and the end of your range. That is done with the method positionFromPosition:offset, which returns a position from another position and a character offset.

- (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];
}

這篇關(guān)于從 NSRange 創(chuàng)建 UITextRange的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

KIF: How to auto-run/stress test an iOS app to find the cause of a rare UI bug?(KIF:如何自動(dòng)運(yùn)行/壓力測(cè)試 iOS 應(yīng)用程序以找出罕見 UI 錯(cuò)誤的原因?)
Can#39;t change target membership visibility in Xcode 4.5(無法更改 Xcode 4.5 中的目標(biāo)成員身份可見性)
UITableView: Handle cell selection in a mixed cell table view static and dynamic cells(UITableView:在混合單元格表視圖靜態(tài)和動(dòng)態(tài)單元格中處理單元格選擇)
How to remove Address Bar in Safari in iOS?(如何在 iOS 中刪除 Safari 中的地址欄?)
iOS 5 SDK is gone after upgrade to Xcode 4.5(升級(jí)到 Xcode 4.5 后,iOS 5 SDK 消失了)
Having trouble creating UIImage from CIImage in iOS5(在 iOS5 中從 CIImage 創(chuàng)建 UIImage 時(shí)遇到問題)
主站蜘蛛池模板: 成人av在线网站 | 亚洲成人网在线观看 | 四色永久| 91在线观看 | 在线小视频 | 国产剧情一区 | 久久久久国产精品午夜一区 | 日韩精品一区二区三区老鸭窝 | 中文字幕日韩一区 | 国产精品久久久久婷婷二区次 | 国内精品视频在线观看 | 欧美日韩在线视频一区 | 天天干天天操天天看 | 亚洲精品一区二区三区蜜桃久 | 一级黄色毛片 | 日韩欧美在线观看 | 日韩高清中文字幕 | 91色综合 | 国产欧美一区二区三区另类精品 | 亚洲国产成人久久久 | 99pao成人国产永久免费视频 | 麻豆一区二区三区 | 一区二区三区四区在线 | 国产一区不卡 | 国产精品一区二区免费 | 草久久| 欧美美女爱爱视频 | 日韩中文久久 | 久久九七| 欧美精品一区二区三区在线播放 | 欧美成人一区二区三区片免费 | 精品综合久久久 | 免费三级网站 | 亚洲一区二区三区在线免费 | 亚洲区中文字幕 | 97成人在线 | 成人在线观看中文字幕 | 青春草国产| 久久久久免费精品国产小说色大师 | 亚洲成av人片在线观看 | 免费一级欧美在线观看视频 |