使用contentScaleFactor属性缩放UITextView [英] Scaling UITextView using contentScaleFactor property

查看:132
本文介绍了使用contentScaleFactor属性缩放UITextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建更高分辨率的UIView图像,特别是UITextView。

I am trying to create a higher resolution image of a UIView, specifically UITextView.

这个问题和答案正是我想要弄清楚的:

This question and answer is exactly what I am trying to figure out:

stackoverflow

但是,当我这样做时,我的文字仍然模糊:

But, when I do the same, my text is still blurry:

self.view.transform = CGAffineTransformMakeScale(2.f, 2.f);
[myText setContentScaleFactor:2.f]; // myText is a subview of self.view object

我也在Apple样本中尝试过相同的向UILabel投射UICatalog,它也很模糊。

I have also tried the same in the Apple sample project "UICatalog" to UILabel's and it is also blurry.

我无法理解为什么它可以从另一个问题为Warrior工作而不是我。我会问那里 - 但我似乎无法在那里留下评论或问题。

I can't understand why it would work for Warrior from the other question and not for me. I would have asked there - but I can't seem to leave a comment or a question there.

任何建议都将不胜感激,谢谢。

Any suggestions would be greatly appreciated, thanks.

推荐答案

设置 contentScaleFactor contentsScale 实际上是关键,正如@dbotha所指出的那样,但是你必须分别遍历视图和层次结构,以便到达实际进行文本渲染的每个内部 CATiledLayer 。添加屏幕比例也可能有意义。

Setting the contentScaleFactor and contentsScale is in fact the key, as @dbotha pointed out, however you have to walk the view and layer hierarchies separately in order to reach every internal CATiledLayer that actually does the text rendering. Adding the screen scale might also make sense.

所以正确的实现是这样的:

So the correct implementation would be something like this:

- (void)updateForZoomScale:(CGFloat)zoomScale {
    CGFloat screenAndZoomScale = zoomScale * [UIScreen mainScreen].scale;
    // Walk the layer and view hierarchies separately. We need to reach all tiled layers.
    [self applyScale:(zoomScale * [UIScreen mainScreen].scale) toView:self.textView];
    [self applyScale:(zoomScale * [UIScreen mainScreen].scale) toLayer:self.textView.layer];
}

- (void)applyScale:(CGFloat)scale toView:(UIView *)view {
    view.contentScaleFactor = scale;
    for (UIView *subview in view.subviews) {
        [self applyScale:scale toView:subview];
    }
}

- (void)applyScale:(CGFloat)scale toLayer:(CALayer *)layer {
    layer.contentsScale = scale;
    for (CALayer *sublayer in layer.sublayers) {
        [self applyScale:scale toLayer:sublayer];
    }
}

这篇关于使用contentScaleFactor属性缩放UITextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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