Question

I'm using CoreTextView to render some html formatted text into a custom view. I'm trying to learn how it works (and I'm a novice with iOS), so I was playing around with the example provided (which does not scroll by default) and I've managed to draw a container rectangle for the content (right now on a red bg to highlight it). My problem is that I don't get how to make it scrollable. I know how to make scrollable views in the storyboard, but I'm trying to do everything programmatically, and I'm out of luck right now.. Here's the code that generates the rectangle:

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);
Was it helpful?

Solution

You'll need to create a UIScrollView wrapper and set the proper 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];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top