Iphone UITextView位置

Iphone UITextView位置,iphone,cocoa-touch,uikit,uitextview,Iphone,Cocoa Touch,Uikit,Uitextview,有没有办法在UITextView中找到YPO,或者/或者找到当前标记处于活动状态的行?您需要进行一些计算 通过查找光标位置 NSRange cursorPosition = [tf selectedRange]; 来自光标位置的子字符串使用此子字符串计算字符串的宽度 sizeWithFont:constrainedToSize: 然后除以文本视图宽度的宽度。。它会告诉你光标在哪一行。。。这在逻辑上似乎是正确的。。。我还没试过。。。试试看,让我知道它是否工作。类似的内容: - (int) g

有没有办法在UITextView中找到YPO,或者/或者找到当前标记处于活动状态的行?

您需要进行一些计算 通过查找光标位置

NSRange cursorPosition = [tf selectedRange];
来自光标位置的子字符串使用此子字符串计算字符串的宽度

sizeWithFont:constrainedToSize: 
然后除以文本视图宽度的宽度。。它会告诉你光标在哪一行。。。这在逻辑上似乎是正确的。。。我还没试过。。。试试看,让我知道它是否工作。

类似的内容:

- (int) getCurrentLine: (UITextView *) textView{
    int pos = textView.selectedRange.location;
    NSString *str =textView.text;
    NSCharacterSet *charset = [NSCharacterSet whitespaceAndNewlineCharacterSet];
    int num = pos;
    for (; num< str.length; num++){
        unichar c = [str characterAtIndex:num];
        if ([charset characterIsMember:c]) break;
    }
    str = [str substringToIndex:num];

    CGSize tallerSize =  CGSizeMake(textView.frame.size.width - 16, 999999);
    CGSize lc1 = [@"Yyg" sizeWithFont: textView.font constrainedToSize:tallerSize lineBreakMode:UILineBreakModeWordWrap];
    CGSize lc = [str sizeWithFont: textView.font constrainedToSize:tallerSize lineBreakMode:UILineBreakModeWordWrap];
    lc.height = lc.height / lc1.height;
    return lc.height;
}
-(int)getCurrentLine:(UITextView*)textView{
int pos=textView.selectedRange.location;
NSString*str=textView.text;
NSCharacterSet*charset=[NSCharacterSet whitespaceAndNewlineCharacterSet];
int num=pos;
for(;num