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:
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
I have also tried the same in the Apple sample project "UICatalog" to UILabel's and it is also blurry.
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.
Be sure to apply the contentScaleFactor to all subviews of the UITextView. I've just tested the following with a UITextView and found it to work:
UITextView has
textInputView
property, which "both draws the text and provides a coordinate system" (https://developer.apple.com/reference/uikit/uitextinput/1614564-textinputview)So i'm using the following code to scale UITextView - without any font changes, without using any "CALayer" property and keeping high quality:
Comment the last line if you need low quality (but better performance) scaling.
Transform uses view.center as scaling center point, so adding a 'translate transform' is needed to scale around view corner.
Setting the
contentScaleFactor
andcontentsScale
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 internalCATiledLayer
that actually does the text rendering. Adding the screen scale might also make sense.So the correct implementation would be something like this: