I have a subclass of UILabel, which is supposed to update its text when the user types something. Naturally, as the length of text increases, the size of the label must adjust to accommodate the text. I called the sizeToFit method, and while the label adjusts its width correctly, the bottom of the text is cut off. The problem is that the text includes subscripts and superscripts , and the label is not adjusting itself with the subscripts in consideration (for example, with H₂O the bottom of the two is cut off).
Can I override sizeToFit or sizeThatFits: to increase the height of the label?
EDIT:
- (void) addCompound {
self.currentLabel = [[FormulaLabel alloc] initWithFrame:CGRectMake(10, 10, 100, 50)];
[self addSubview:self.currentLabel];
[self.currentLabel sizeToFit];
// Right now self.currentlabel.text = "". However, I've confirmed thru NSLogging that letters are added to self.currentLabel.text as the user types on the keyboard. Also, the text displays properly (as long as it's within the original frame) when I remove [sel.currentLabel sizeToFit]
}
- (void)sizeToFit { [super sizeToFit]; self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, 100); }
– Mahir