Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/44.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
Iphone 如何使UITextView像Notes应用程序一样使用文本展开_Iphone_Sdk_Uitextview - Fatal编程技术网

Iphone 如何使UITextView像Notes应用程序一样使用文本展开

Iphone 如何使UITextView像Notes应用程序一样使用文本展开,iphone,sdk,uitextview,Iphone,Sdk,Uitextview,如何使UITextView使用其中的文本进行扩展?您可以尝试以下方法 UITextView *textView; // your UITextView NSString *text; // the text that you want to place in the UITextView UIFont *textViewFont; // the font that you are using for your UITextView CGSize size = {255,2000.0f}; /

如何使UITextView使用其中的文本进行扩展?

您可以尝试以下方法

UITextView *textView; // your UITextView
NSString *text; // the text that you want to place in the UITextView
UIFont *textViewFont; // the font that you are using for your UITextView

CGSize size = {255,2000.0f};  //The default width, and max height you want to use

CGSize newSize = [text sizeWithFont:textViewFont
                 constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];

textView.frame = CGRectMake(0,0,newSize.width, newSize.height);
你可以试试这个

CGRect frame = textView.frame;
frame.size.height = [textView contentSize].height;
textView.frame = frame;

您是否在UITableView中使用UITextView

假设您在UITableView中使用UITextView。为了使UITextView高度动态符合其中的内容,我们需要注意以下事项:-

确保正确给定UITextView约束。e、 g:我在tableview单元格中使用了XIB,在单元格内部我有一个UITextView。因此,我将对UITextView 0的所有四个边进行约束,例如:顶部、底部、前导、尾随。这取决于你的要求

确保UITextView属性的autoscroll已禁用。应该关掉了

确保TableView单元格高度为UITableView.automaticDimension

现在,在“textViewDidChange”委托方法中,只需添加以下代码:

        UIView.setAnimationsEnabled(false)
        tableView?.beginUpdates()
        tableView?.endUpdates()
        UIView.setAnimationsEnabled(true)
现在,当您键入init时,您的文本视图将自动展开