Iphone 在texView之后放置一个名为“发送”的UIButton。TextView内容在每种情况下都会有所不同,具体取决于xml解析的字符串
在我的应用程序中,我有一个文本视图。我正在我的文本视图中以编程方式显示一些字符串内容。我必须在texView之后放置一个名为“发送”的UIButton。这里的意思是我正在解析xml文件中的字符串内容。因此,字符串长度在每种情况下都应该有所不同 但我必须在文本视图后放置一个发送按钮。怎么做。我找到了下面的代码片段。但有时它会在文本视图后的位置显示发送按钮。有时它不在重叠的位置。帮帮我 新闻第二部分是我的文本视图Iphone 在texView之后放置一个名为“发送”的UIButton。TextView内容在每种情况下都会有所不同,具体取决于xml解析的字符串,iphone,ios,Iphone,Ios,在我的应用程序中,我有一个文本视图。我正在我的文本视图中以编程方式显示一些字符串内容。我必须在texView之后放置一个名为“发送”的UIButton。这里的意思是我正在解析xml文件中的字符串内容。因此,字符串长度在每种情况下都应该有所不同 但我必须在文本视图后放置一个发送按钮。怎么做。我找到了下面的代码片段。但有时它会在文本视图后的位置显示发送按钮。有时它不在重叠的位置。帮帮我 新闻第二部分是我的文本视图 int secondStringLength = secondStr.
int secondStringLength = secondStr.length;
int height = secondStringLength / 48;
height = height * 18.0;
//newsSecondPart is my textView
CGRect newsSecondPartFrame = newsSecondPart.frame;
if (height < 400)
newsSecondPartFrame.size.height = height + 475; // for text unhiding
else
newsSecondPartFrame.size.height = height + 975; // for text unhiding
if (secondStringLength > 5000) {
newsSecondPartFrame.size.height += 150;
}
newsSecondPart.frame = newsSecondPartFrame;
CGRect viewFrame = superView.frame;
viewFrame.size.height = newsSecondPartFrame.size.height + 200 ;
superView.frame = viewFrame;
scrollView.contentSize = superView.bounds.size;
scrollView.contentSize = CGSizeMake( 0, newsSecondPartFrame.size.height+300);
newsFirstPart.text = firstStr;
newsSecondPart.text = secondStr;
请帮助我……要获取textview的动态大小,您需要以下代码
CGSize size = [secondStr sizeWithFont:txtView.font constrainedToSize:CGSizeMake(txtView.frame.size.width,10000)];
size.height +=10;
这样,您将获得字符串的动态高度
现在您可以设置textview的框架
CGRect frame = txtView.frame;
frame.size.height= size.height;
txtView.frame = frame;
现在您可以设置按钮框:
CGRect frame = btnSend.frame;
frame.origin.y = txtView.frame.origin.y + txtView.frame.size.height+10;
btnSend.frame = frame;
希望这有帮助