0

I'm trying to let the user to adjust himself the font size to read the content of the app. therefor i put a slider that if the user swipe right, the fonts will grow and left means that the fonts size will be smaller. it works fine, but the problem is that sometimes the scrollView content size is not getting the new content size. This is my method:

- (IBAction)enlargeLabelWithSlider:(id)sender{

UISlider *slider = (UISlider *)sender;
int font = 0;
int currentSliderValue = (int)slider.value;

if (currentSliderValue<=lastSilderValue) /* Every time the method call, at the end lastSilderValue = currentSliderValue*/
{
    // Need to increase
    font =lastSilderValue - currentSliderValue;

    [self.gameTitleLabel setFont:[UIFont fontWithName:self.gameTitleLabel.font.fontName size:self.gameTitleLabel.font.pointSize+font]];
    [self.gameScoreLabel setFont:[UIFont fontWithName:self.gameScoreLabel.font.fontName size:self.gameScoreLabel.font.pointSize+font]];
    self.gameStateLabel.font = [UIFont systemFontOfSize:self.gameStateLabel.font.pointSize+font];
}
else
{
    // Need to decrease
    font =currentSliderValue - lastSilderValue;

    [self.gameTitleLabel setFont:[UIFont fontWithName:self.gameTitleLabel.font.fontName size:self.gameTitleLabel.font.pointSize-font]];
    [self.gameScoreLabel setFont:[UIFont fontWithName:self.gameScoreLabel.font.fontName size:self.gameScoreLabel.font.pointSize-font]];
    self.gameStateLabel.font = [UIFont systemFontOfSize:self.gameStateLabel.font.pointSize-font];
}
lastSilderValue = currentSliderValue;

CGFloat height = self.gameStateLabel.frame.origin.y+self.gameStateLabel.frame.size.height+20; 
CGSize size = CGSizeMake(self.ScrollView.frame.size.width, height);
self.ScrollView.contentSize = CGSizeMake(size.width, size.height); // i used self.gameStateLabel.frame.origin.y because it's the last label on the view.

}

can someone tell me why is this happening? Thanks.

Oren
  • 85
  • 7

1 Answers1

0

I don't see any change to the UILabel frame. Maybe you have to adapt this frame to the new font size and then try to modify the scrollview contentSize property. This will be helpful: Adjust UILabel height depending on the text

Community
  • 1
  • 1
Luca D'Alberti
  • 4,434
  • 3
  • 26
  • 41
  • i gave the UILabels constraints at the InterfaceBuilder and set numberOfLines to 0 there...the labels adjust correctly to the new font size.. the problem is that only sometimes the scrollView is not getting the correct size... – Oren Nov 28 '14 at 21:03