我想创建一个应用程序,其功能类似于 iOS 7 的 Notes 应用程序。基本上,顶部有一排日期和时间。
我的解决方案是将 UITextView 放在 UITableView 中。第一行是带有日期和时间的 UILabel,第二行是 UITextView。
我根据 UITextView ContentSize 更改 UITextView 和 UITableViewCell 的高度。
问题是 UITextView 尺寸很大,所以当用户按下返回键时它不会自动滚动。
有什么办法可以让它正常滚动吗?
最佳答案
UITextView
是 UIScrollView
的子类。我将建议一种实现类似功能的替代方法。添加标签 View 作为 TextView 的 subview ,并设置标签高度的 contentInset
top 值。
UILabel* label = [UILabel new];
label.text = @"Test";
[label sizeToFit];
CGRect frame = label.frame;
frame.origin.y -= frame.size.height;
[label setFrame:frame];
[self.textView addSubview:label];
[self.textView setContentInset:UIEdgeInsetsMake(label.frame.size.height, 0, 0, 0)];
示例项目: http://sdrv.ms/16JUlVD
关于ios - 当按下回车键时,UITableView 中的 UITextView 不会向上滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19182404/