2

CoreTextViewを使用して、html 形式のテキストをカスタム ビューにレンダリングしています。私はそれがどのように機能するかを学ぼうとしています(そして私はiOSの初心者です)ので、提供された例(デフォルトではスクロールしません)で遊んでいて、コンテンツのコンテナ長方形を描くことができました(現在、それを強調するために赤い背景で)。私の問題は、スクロール可能にする方法がわからないことです。ストーリーボードでスクロール可能なビューを作成する方法は知っていますが、プログラムですべてを実行しようとしていますが、今はうまくいきません.長方形を生成するコードは次のとおりです。

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;

int widthInt = (int)roundf(screenWidth)-20;
int heightInt= (int)roundf(screenHeight)-60;
m_coreText=[[CoreTextView alloc] initWithFrame:CGRectMake(10, 50, widthInt, heightInt)];
m_coreText.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
m_coreText.backgroundColor=[UIColor redColor];
m_coreText.contentInset=UIEdgeInsetsMake(10, 10, 10, 10);
4

1 に答える 1

1

UIScrollView ラッパーを作成し、適切な contentSize を設定する必要があります。

m_coreText.frame=CGRectMake(0, 0, self.view.bounds.size.width, [m_coreText sizeThatFits:CGSizeMake(self.view.bounds.size.width, MAXFLOAT)].height);

UIScrollView* scroll=[[UIScrollView alloc] initWithFrame:self.view.bounds];
scroll.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
scroll.contentSize=m_coreText.frame.size;
[scroll addSubview:m_coreText];
[self.view addSubview:scroll];
于 2013-05-09T16:29:29.530 に答える