ios - 淡化 UITextView 中文本范围的 alpha 值

标签 ios swift uitextview range fade

我有一个 UITextView,其中包含几个串联的 NSAttributedString。我有一种机制可以检测哪个字符串或单词被点击,并希望能够淡入淡出字符串的 alpha 值。

是否可以以这种方式仅操作 TextView 中的文本范围?据我了解,似乎只能更改整个 TextView 的 alpha 值。

最佳答案

您可能会考虑针对字符串的该范围降低 NSForegroundColorAttributeName 属性值的 alpha。如果您希望完全淡化文本,请将 alpha 降低到零,这将为您提供您正在寻找的确切效果。

[yourAttributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:255.0/255.0 green:0.0 blue:0.0 alpha:0.05]range:rangeOfAlphaText];

关于ios - 淡化 UITextView 中文本范围的 alpha 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25494995/

相关文章:

ios - 使用 CoreData 和依赖注入(inject) - 线程 1 : Fatal error: init(coder:) has not been implemented

iphone - UITextView 文本颜色自动变得与背景颜色相同

ios - 使用排除路径计算 TextView 的单元格高度

ios - 编辑时 tableView 中没有 didSelectRowAtIndexPath()

ios - 从数据库加载实体而不是直接从数据库提取数据

Swift:打印除​​法的小数精度

uitextview - 在富 UITextView (iOS 6) 中使用 NSUndoManager 撤消操作

iphone - 将联系人存储在 iPhone 自己的应用程序中

ios - 我如何在 swift 3 的一个 View Controller 中填充两个不同的 TableView

html - 将字体属性添加到 HTML 渲染的 UILabel swift