KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
This is a little different from all the other "How do I center the text in a UILabel " questions here... I have a UILabel with some text in it, I want to center the text vertically in the UILabel . What's the big deal, right? That's the default. The problem comes because my text is dynamic and I have autoshrink turn on. As the text grows larger, the font size shrinks. You get this behavior. Notice that the font baseline has not moved, I want it to move so the numbers are centered vertically in the UILabel's frame. Easy, right? I just remember the frame's original center in viewDidLoad self.workoutTimeCenter = _workoutTimeLabel.center; and then I call sizeToFit after I change the the text, right? [_workoutTimeLabel sizeToFit]; _workoutTimeLabel.center = _workoutTimeCenter; Well, sizeToFit did, I guess, exactly what it was supposed to do, resize the frame so the text fits without shrinking! How can I vertically center the text in a UILabel while respecting baselines and autoshrink? (Note, an iOS5 and later solution is fine and I can even deal with an iOS6 and later solution.)
Tags (comma-separated)
Save Edits
Cancel