I have a UITextView that is supposed to have one line of text.
The size font is controlled by a slider. As the user controls the slider, I calculate the new UITextView size using (this is the method called by the slider as it moves).
- (void) changeFontSize:(id)sender {
UISlider *slider = (UISlider *)sender;
CGFloat newSize = (CGFloat)[slider value];
myTextView.font = [UIFont boldSystemFontOfSize:newSize];
[self adjustBoxforSize:myTextView.text];
}
- (void) adjustBoxForSize:(NSString*)myText {
CGFloat fontSize = myTextView.font.pointSize;
CGSize newSize =
[myText sizeWithFont:[UIFont boldSystemFontOfSize:fontSize]];
newSize.width = newSize.width * 1.5; // make it 50% larger
newSize.height = newSize.height * 1.5; // make it 50% taller
CGRect myFrame = CGRectMake(0.0f, 0.0f, newSize.width, newSize.height);
myTextView.frame = myFrame;
}
If I reduce the font, this is the result
The question is: how can the text be out of the textview if I am scaling it to fit and indeed making it 50% larger??
am I missing something? It seems that sizeWithFont is not calculating the size correctly.
Thanks.