1
コンテンツに応じて可変サイズのテキストボックスをサポートするアプリケーションを作成しようとしています。 UITextViewのサイズは4行まで増加し、スクロールを有効にする必要があります。UItextViewの行数を取得する
テキストを入力するときに行数を取得できません。
私はそれを行うには何らかの方法を提案してください。サンプルコードスニペットは高く評価されます。
ありがとうございます!
コンテンツに応じて可変サイズのテキストボックスをサポートするアプリケーションを作成しようとしています。 UITextViewのサイズは4行まで増加し、スクロールを有効にする必要があります。UItextViewの行数を取得する
テキストを入力するときに行数を取得できません。
私はそれを行うには何らかの方法を提案してください。サンプルコードスニペットは高く評価されます。
ありがとうございます!
私はこの問題を一時的に解決しようとしました。 View Controllerの - (void)textViewDidChange:(UITextView *)textView
メソッドに次のコードを追加し、IBのファイル所有者に代理人を変更することができます。
float adjustvar;
if ([textView.text isEqualToString:@""]) {
//change these values according to your requirement as they are hard coded to adjust cursor and size of the textview
adjustvar = 37.0;
textView.contentInset = UIEdgeInsetsMake(6 ,0 ,0 ,0);
}
else {
adjustvar = textView.contentSize.height;
}
CGRect temp = textView.frame;
temp.origin.y = textView.frame.origin.y + textView.frame.size.height - adjustvar;
temp.size.height = adjustvar;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
[UIView setAnimationsEnabled:YES];
if (temp.size.height > 142.0) {
textView.scrollEnabled = YES;
}
else {
textView.scrollEnabled = NO;
textView.frame = temp;
}
[UIView commitAnimations];`
これが役立ちます。より良い解決策があれば親切に助けてください。
おかげ
[行のUITextView数を見つける方法]の可能な重複(https://stackoverflow.com/questions/7320361/how-to-find-uitextview-number-of-lines) – iWheelBuy