1
votes

On detailview (Scrollview) in my app I have a UILabel that gets text that will have about 1000 words.

I want to resize it so the label fits - works fine so far

-(void) viewDidAppear:(BOOL)animated {
NSString *message = storycontent.text;
CGSize maximumLabelSize = CGSizeMake(280,5000);
CGSize expectedLabelSize = [message sizeWithFont:storycontent.font constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByWordWrapping];
CGRect newFrame = storycontent.frame;
newFrame.size.height = expectedLabelSize.height;
storycontent.frame = newFrame;
}

When navigation to that detailview the label is resized as expected. Now the weird thing: The moment I want to scroll down the UILabel snaps back to the initial size, so that only the first words are visible.

What can I do to avoid that behavior?

UPDATE: When i delete the label and put in a new one it works fine. The strange behavior starts the moment i change the font size to something other then 17.

1
Rather than taking a Label take a textView - Manu
i get the same behavior by a textview. its resizing to the initial height of the object, when i start scrolling :( - alexdd55
can you please log your newFrame and storyContent frame - Manu
Are you using autolayout? - Mark Kryzhanouski
Go to the File inspector in interface builder, and untick "Use Auto Layout". - Mark Kryzhanouski

1 Answers

0
votes

My current solution (or workaround) was now to deactivate "Use Autolayout" (thx to Mark Kryzhanouski), which solves the snapping issue.

With not having the Autolayout the ScrollView does not automatically resize, so i added

@property (retain, nonatomic) IBOutlet UIScrollView *scroller;

and calculated a new FrameSize for it with the content size i already know from above, plus the static content that will be shown always.

NSString *message = storycontent.text;
CGSize maximumLabelSize = CGSizeMake(280,5000);
CGSize expectedLabelSize = [message sizeWithFont:storycontent.font constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByWordWrapping];

[scroller setContentSize:CGSizeMake(280,expectedLabelSize.height + 400)];

Maybe there is a way to do the same with "Use Autolayout" activated?!