Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pinch-to-zoom UILabel

I'm handling a pinch gesture, and I am scaling a UILabel like this:

CGFloat factor = sender.scale;
view.transform = CGAffineTransformScale(view.transform, factor, factor);

The problem is when I zoom-in (make the label larger) it wont redraw itself, i.e. it becomes blurry. How do I make it sharp again?

like image 724
Mikka Johnson Avatar asked Nov 04 '22 19:11

Mikka Johnson


1 Answers

The reason this happens is that transforms are applied to the rendered bitmap of the view's layer.

If you want to have the label's contents scaled adjust the contentsScale, too:

CGFloat scaleFactor = ...

view.layer.contentsScale = [UIScreen mainScreen].scale + scaleFactor;
view.transform           = CGAffineTransformMakeScale( scaleFactor, scaleFactor );
like image 52
karwag Avatar answered Nov 11 '22 06:11

karwag