izaslavs
izaslavs

Reputation: 403

scrolling CoreText in UIScrollView

I am experimenting with CoreText, one of the problems i have is that content isn't scrollable and idk how to make it scrollable... with labels this code works:

//Calculate the expected size based on the font and linebreak mode of your label
CGSize maximumLabelSize = CGSizeMake(300,9999);

CGSize expectedLabelSize = [labelText sizeWithFont:label.font
                                  constrainedToSize:maximumLabelSize 
                                      lineBreakMode:UILineBreakModeTailTruncation];

//adjust the label the the new height.
CGRect newFrame = label.frame;
newFrame.size.height = expectedLabelSize.height;
label.frame = newFrame;

my test project: http://dl.dropbox.com/u/47384598/AA_CoreText.zip

but what should i do with CoreText? Any help highly appreciated!

Upvotes: 1

Views: 576

Answers (1)

Maurizio
Maurizio

Reputation: 4169

You should probably render your CoreText frames into a UIView. Then, add this UIView to your UIScrollView as a subview and set the contentSize of the UIScrollView such that the contentSize is large enough to fit your UIView holding the CoreText.

Note that if the contentSize of the UIScrollView is less than the size of the view on the screen, it will not need to scroll.

Upvotes: 1

Related Questions