簡體   English   中英

如何使用 Swift 降低 UITextView 中文本的質量

[英]How to reduce the quality of the text inside UITextView with Swift

我正在嘗試在發送消息之前降低消息的質量,例如,如果連接不佳,我想模糊UITextView的文本,如果連接改善或互聯網恢復,則刪除模糊並顯示正常UITextView文本。 我試過使用CATextLayer不起作用。 有沒有辦法實現這一目標?

cell.messageTextView.text = theText

let textLayer = CATextLayer()
textLayer.string = cell.messageTextView.text
textLayer.contentsScale = 0.2
cell.messageTextView.layer.addSublayer(textLayer)

在此處輸入圖片說明

您可以通過將圖層柵格化並縮小其比例來降低圖層的質量:

let badQualityRatio: CGFloat = 4
textView.layer.shouldRasterize = true
textView.layer.rasterizationScale = UIScreen.main.scale/badQualityRatio

結果:

結果

您可以將rasterizationScale設置為 0 和UIScreen.main.scale之間的任意數字

你可以嘗試這樣的事情:

let blurEffect = UIBlurEffect(style: .systemUltraThinMaterial)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = cell.view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
cell.view.addSubview(blurEffectView)

在表格視圖單元格的頂部添加具有模糊效果的 UIVisualEffectView。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM