使用Swift将删除线添加到iOS 11中的NSAttributedString [英] Adding strikethrough to NSAttributedString in iOS 11 with Swift
本文介绍了使用Swift将删除线添加到iOS 11中的NSAttributedString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在删除线正常工作方面存在一些问题.目前,我正在执行以下操作:
Having some issues getting strikethrough to work. Currently I'm doing the following:
theString.addAttributes([
NSAttributedStringKey.strikethroughStyle: NSUnderlineStyle.styleSingle.rawValue,
NSAttributedStringKey.strikethroughColor: UIColor.white
], range: NSMakeRange(0, 1))
虽然没有显示任何删除线.有任何想法吗?我似乎找不到任何有效的方法.
It's not showing any sort of strikethrough though. Any ideas? I can't seem to find anything that works.
推荐答案
我用它来删除Xcode9/iOS11/Swift4 env中的文本
I use this to strike through a text in Xcode9/iOS11/Swift4 env
let strokeEffect: [NSAttributedStringKey : Any] = [
NSAttributedStringKey.strikethroughStyle: NSUnderlineStyle.styleSingle.rawValue,
NSAttributedStringKey.strikethroughColor: UIColor.red,
]
let strokeString = NSAttributedString(string: "text", attributes: strokeEffect)
这篇关于使用Swift将删除线添加到iOS 11中的NSAttributedString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文