Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monotouch UIScrollView, Text blurs when zooming in

With regards to Monotouch IOS development:

Can anyone write me a code snippet, or refer me to one, of how to have Text inside of a UIScrollView and have the text NOT get blurry as you zoom in? Either using CALayer or just re-rendering it once zoom has ended. I have been attempting this for the past week and cannot seem to get anything working. I have not found any good examples regarding this either.

I found a similar post on stack overflow citing they used CALayer, but not example was given on how to do this: Text getting blur on zoom-in

Thanks all

like image 429
LampShade Avatar asked Jan 27 '26 18:01

LampShade


1 Answers

You need to set the ContentsScale property of the layer based on the zoom factor.

In your zooming ended method

public override void ZoomingEnded(UIScrollView scrollView, UIView withView, float atScale)
{
    withView.Layer.ContentsScale =  UIScreen.MainScreen.Scale * atScale;
    withView.SetNeedsDisplay();
}

Note: This assumes you are using a UIScrollViewDelegate

The reason you multiply by the MainScreen scale is to support retina displays.

I'm updating the views layer, but you will need to update which ever layer is causing you trouble. You also need to apply the scale to all affected sub layers yourself.

Hope that helps.

like image 144
Jamie Avatar answered Jan 30 '26 12:01

Jamie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!