Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 获取uitextview中字符串的结尾_Ios_Height_Uilabel_Uitextview_Xib - Fatal编程技术网

Ios 获取uitextview中字符串的结尾

Ios 获取uitextview中字符串的结尾,ios,height,uilabel,uitextview,xib,Ios,Height,Uilabel,Uitextview,Xib,我想创建一个消息框,就像电报和其他聊天一样,在框的下面有时间 但是,如果文本结束于行尾,则时间标签应位于下一行,否则应保持在同一行 所以,我想要这样的东西: 如何在我的xib中实现这一点,或者通过编程实现 感谢您的关注,您可以计算文本视图中最后一个字符的位置,并检查是否有足够的空间放置时间标签,然后将其显示出来,否则将其添加到新行 UITextPosition *Pos2 = [textView positionFromPosition:textView.endOfDocument offse

我想创建一个消息框,就像电报和其他聊天一样,在框的下面有时间

但是,如果文本结束于行尾,则时间标签应位于下一行,否则应保持在同一行

所以,我想要这样的东西:

如何在我的xib中实现这一点,或者通过编程实现


感谢您的关注,

您可以计算文本视图中最后一个字符的位置,并检查是否有足够的空间放置时间标签,然后将其显示出来,否则将其添加到新行

UITextPosition *Pos2 = [textView positionFromPosition:textView.endOfDocument offset:0];
UITextPosition *Pos1 = [textView positionFromPosition:textView.endOfDocument offset:-1];
UITextRange *range = [textView textRangeFromPosition:Pos1 toPosition:Pos2];
CGRect lastCharRect = [textView firstRectForRange:(UITextRange *)range];
CGFloat freeSpace = textView.frame.size.width - lastCharRect.origin.x - lastCharRect.size.width;
if (freeSpace > requiredWidthForTimeLabel) {
    //add time label to the last line     
} else {
    //add time label on a new line
}

实际上这是自定义的
UITableViewCell
不是任何
UITextField
是的,但在我的情况下,它是类似的,不是吗?我有一个UITableViewCell,里面有一个UITextView。