gpt4 book ai didi

ios - iPhone : UITextView not expanding while editing

转载 作者:行者123 更新时间:2023-12-01 17:44:25 24 4
gpt4 key购买 nike

我在 ScrollView 上使用 UITextView ...我希望它在我写东西时自动扩展......但我无法做到......

textViewBusiness = [[UITextView alloc] initWithFrame:CGRectMake(25,332,268,60)];
textViewBusiness.text=strMyBusiness;
textViewBusiness.editable=NO;
textViewBusiness.font = [UIFont fontWithName:@"Arial" size: 17.0];
textViewBusiness.layer.borderWidth = 2.0f;
textViewBusiness.layer.borderColor = [[UIColor grayColor] CGColor];
textViewBusiness.backgroundColor = [UIColor clearColor];
[textViewBusiness setTextColor:[UIColor blackColor]];
[self.scrollView addSubview: textViewBusiness];

CGRect frame = textViewBusiness.frame;
frame.size.height = textViewBusiness.contentSize.height;
textViewBusiness.frame = frame;

这段代码对我不起作用...

谢谢

最佳答案

确保设置了文本字段的委托(delegate)...

someTextField.delegate = self;

然后在相应的文本字段委托(delegate)方法中调整 textView 的大小。
- (void)textViewDidChange:(UITextView *)textView;

- (void) textViewDidEndEditing:(UITextView *)textView;

您在上面添加的代码是正确的。只要确保它在正确的位置。
- (void)textViewDidChange:(UITextView *)textView
{
CGRect frame = textView.frame;
frame.size.height = textView.contentSize.height;
textView.frame = frame;
}

Dynamic expand UITextView

关于ios - iPhone : UITextView not expanding while editing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10617381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com