[英]How to reduce the quality of the text inside UITextView with Swift
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
.我正在尝试在发送消息之前降低消息的质量,例如,如果连接不佳,我想模糊UITextView
的文本,如果连接改善或互联网恢复,则删除模糊并显示正常UITextView
文本。 I have tried using CATextLayer
doesn't work.我试过使用CATextLayer
不起作用。 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
you can set the rasterizationScale
any number between 0 and UIScreen.main.scale
您可以将rasterizationScale
设置为 0 和UIScreen.main.scale
之间的任意数字
You could try something like this:你可以尝试这样的事情:
let blurEffect = UIBlurEffect(style: .systemUltraThinMaterial)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = cell.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
cell.view.addSubview(blurEffectView)
Adding a UIVisualEffectView with blur effect on top of your table view cell.在表格视图单元格的顶部添加具有模糊效果的 UIVisualEffectView。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.