如何使用 Swift 降低 UITextView 中文本的质量 [英] How to reduce the quality of the text inside UITextView with Swift
问题描述
我试图在发送消息之前降低消息的质量,例如,如果连接很差,我想模糊 UITextView
中的文本,如果连接改善或互联网出现返回,然后移除模糊并在 UITextView
中显示普通文本.我试过使用 CATextLayer
不起作用.有什么办法可以做到这一点吗?
I'm trying to reduce the quality of a message before its being sent, for example if the connect is poor I want to blur out the text in the UITextView
and if connection improves or internet comes back, then remove the blur and show the normal text in the UITextView
. I have tried using CATextLayer
doesn't work. Is there a way I can achieve this?
cell.messageTextView.text = theText
let textLayer = CATextLayer()
textLayer.string = cell.messageTextView.text
textLayer.contentsScale = 0.2
cell.messageTextView.layer.addSublayer(textLayer)
推荐答案
您可以通过将图层栅格化并缩小其比例来降低图层的质量:
You can drop the quality of the layer by making it rasterized and reducing the scale of it:
let badQualityRatio: CGFloat = 4
textView.layer.shouldRasterize = true
textView.layer.rasterizationScale = UIScreen.main.scale/badQualityRatio
结果:
您可以设置 rasterizationScale
0 到 UIScreen.main.scale
you can set the rasterizationScale
any number between 0 and UIScreen.main.scale
这篇关于如何使用 Swift 降低 UITextView 中文本的质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!