Reputation: 600
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)
Upvotes: 0
Views: 915
Reputation: 119340
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
Upvotes: 4
Reputation: 532
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.
Upvotes: 1