如何在调整大小后调整UITextView下的项目?
问题描述:
你好,这是我用它来增加我的UITextView的高度的方法:
如何在调整大小后调整UITextView下的项目?
- (void)textViewDidChange:(UITextView *)textView
{
CGRect frame = textView.frame;
frame.size.height = textView.contentSize.height;
textView.frame = frame;
}
这是工作,问题是调整TextView的我怎样才能正确地调整我的所有的UITextView下的项目后?
钍结构是像如下:
视图
--ScrollView
----的TextView
----布通
----的TextField(后(Rezising TextView的移动这个元件太之后) Rezising textview也移动这个元素)
答
一种方法是,你可能想要使UIButton和UITextField成为视图控制器的属性,以便您可以访问它们并在textViewDidChange方法内更改其框架属性。
例如,在.h文件:
@property (weak, nonatomic) IBOutlet UIButton *button; //if you are using IB
@property (weak, nonatomic) IBOutlet UITextField *textField; //do not forget to link these two in the IB
而在.m文件:
- (void)textViewDidChange:(UITextView *)textView
{
CGRect frame = textView.frame;
frame.size.height = textView.contentSize.height;
textView.frame = frame;
self.button.frame = CGRectMake(updatedButtonFrame);
self.textField.frame = CGRectMake(updatedTextFieldFrame);
}