Alex Rivera | Logout

Zoom UILabel & Re-render font at correct size

Asked 2010-01-02T02:58:12.097
17

I have a multi-line UILabel that I want to enable zooming on.

I embedded it with a UIScrollView and set min zoom to .25 and max zoom to 4. This works well, however my UILabel's font looks rather gross at any zoom level other than 1.

I can handle this method:

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale

in order to re-size the font of my UILabel to something larger, but the view is still zoomed in, so it always looks awful.

Is there any way to make the label's text re-render one I'm done zooming?

It is important that the users current scrolled position in the text not be lost.

(To get a feel for what I'm going for, notice how in Mobile Safari when you zoom the text is scaled/anti-aliased for a split second then it clears up to render well at your current zoom scale)

Edit
Report

2 Answers

8

iOS 4+

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
    scrollView.contentScaleFactor = scale;
    for (UIView *subview in scrollView.subviews) {
        subview.contentScaleFactor = scale;
    }
}

If this gets too intensive and performance is slow, just try setting the contentScaleFactor for only your labels.

answered 2012-11-02T15:09:50.543
2

I tested JEzu's code in iOS 5.1 and 6 beta, it is working for a const text label, but cause other normal label require updating text content fail, i.e. the text is not changed...

I subclass the UILabel as ZoomableLabel with JEzu's answer, and apply the class as the label's custom class and it works fine.

answered 2012-08-30T08:18:04.383

Your Answer