0

以下のように、テキストビューをコンテンツのサイズに拡大しています

CGRect _frame = descriptionText.frame;
_frame.size.height = descriptionText.contentSize.height;
descriptionText.frame = _frame;

コンテンツがビューを超えており、下にスクロールしてテキストを表示できませんでした。

スクロールビューのサイズをこんな風に設定してみた

scrollView.contentSize = CGSizeMake(295,_frame.size.height);

しかし、スクロールに失敗しますが、このような数値を指定すると機能します

scrollView.contentSize = CGSizeMake(295,600);

スクロール ビューのサイズを動的なコンテンツのサイズに設定する必要があります。どうやってやるの?

説明テキストを編集

CGRect descriptionTextViewRect = CGRectMake(15, 185, 280, 85);
descriptionText = [[UITextView alloc] initWithFrame:descriptionTextViewRect];
descriptionText.textAlignment = UITextAlignmentLeft;
descriptionText.text =offerdes;//this is the text fetched from an xml and is dynamic.
descriptionText.editable = NO;
descriptionText.layer.cornerRadius = 5.0;
descriptionText.clipsToBounds = YES;
descriptionText.userInteractionEnabled = YES;
descriptionText.font = [UIFont systemFontOfSize:15];
[scrollView addSubview: descriptionText];
[descriptionText release];
4

2 に答える 2

1

サイズを変更するこのコード セグメントは、テキストビューをスクロール ビューに追加した後に呼び出す必要があります。

この行の後

[scrollView addSubview: descriptionText];

このセグメントを使用できます

CGRect _frame = descriptionText.frame;
_frame.size.height = descriptionText.contentSize.height;
descriptionText.frame = _frame;

私はちょうどそれをテストし、それは動作します

次のことを確認してください

  • テキストビューをスクロールビューに正しく追加していること
  • offerdes が nil でないこと
于 2012-07-03T10:58:20.937 に答える
0

問題はサイズの設定方法ではなく、フレームを格納する変数が正しく設定されていないことです。

descriptionText.contentSize が CGSizeZero を返す理由を追跡するには、コードの他の場所を調べる必要があります。

于 2012-07-03T10:43:36.097 に答える