放大UILabel&以正确的大小重新渲染字体 [英] Zoom UILabel & Re-render font at correct size

查看:353
本文介绍了放大UILabel&以正确的大小重新渲染字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要启用放大的多行 UILabel

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

我嵌入了它一个 UIScrollView 并将最小缩放设置为.25并将最大缩放设置为4.这很有效,但我的 UILabel 是字体在除1以外的任何缩放级别看起来相当粗略。

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.

我可以处理这种方法:

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

为了将我的UILabel的字体重新调整为更大的尺寸,但是视图仍然放大了,所以看起来总是很糟糕。

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?

用户当前滚动位置很重要在文本中不会丢失。

(为了了解我的目的,请注意缩放文本时Mobile Safari中的内容如何缩放/消除锯齿一瞬间然后清除最好以当前缩放比例渲染)

(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)

推荐答案

UIScrollView的内置缩放仅将变换应用于内容视图,这会导致比例系数为1.0以上的任何事物都变得模糊。对于真正清晰的渲染,您需要自己处理缩放。我在这个答案中描述了一大块过程

The UIScrollView's built-in scaling only applies a transform to your content view, which results in blurriness at anything above a scale factor of 1.0. For truly sharp rendering, you'll need to handle the scaling yourself. I describe a chunk of the process in this answer.

您需要手动跟踪内容视图的比例因子,然后在-scrollViewDidEndZooming中:withView:atScale:委托方法你将适用该规模。对于你的UILabel,这意味着要改变字体大小以反映新的比例。

You'll need to keep track of the scale factor of the content view manually, then in the -scrollViewDidEndZooming:withView:atScale: delegate method you'll apply that scale. For your UILabel, that will mean changing the font size to reflect the new scale.

为了保持正确的滚动位置,你需要抓住contentOffset上面的委托方法中的UIScrollView并计算新缩放的UILabel中对应的位置。然后设置滚动视图的contentSize以匹配UILabel的新大小,并使用-setContentOffset:animated:设置新计算的内容偏移量(动画设置为NO)。

In order to maintain the correct scroll position, you'll need to grab the contentOffset of the UIScrollView within the above delegate method and calculate what position that corresponds to in the newly scaled UILabel. You then set the contentSize of the scroll view to match the new size of the UILabel and use -setContentOffset:animated: to set the newly calculated content offset (with animated set to NO).

让数学运算正确有点棘手,但是我在我的一个应用程序中缩放文本时会这样做,这可以在该应用程序的视频演示(大约1/3标记)。

It's a little tricky to get the math right, but I do this when scaling text in one of my applications, which can be seen in the video demonstration of that application (at about the 1/3 mark).

这篇关于放大UILabel&以正确的大小重新渲染字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆