如何在swift 4中交叉攻击单元格按钮
目前我正在使用以下代码来敲击按钮
func testString (titleStr : String) -> NSMutableAttributedString {
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: titleStr)
attributeString.addAttribute(NSBaselineOffsetAttributeName, value: 1, range: NSMakeRange(0, attributeString.length ))
attributeString.addAttribute(NSStrikethroughStyleAttributeName, value: 1, range: NSMakeRange(0, attributeString.length ))
attributeString.addAttribute(NSStrikethroughColorAttributeName, value: UIColor.red, range: NSMakeRange(0, attributeString.length))
return attributeString
}
得到输出像这样1:
如何更改我的代码以获得这样的输出截图qazxsw poi:qazxsw poi
你可以通过使用1实现这一目标。在按钮上方创建并为按钮边缘设置约束 - 在视图上单击鼠标右键并拖动到按钮:
UIBezierPath
按住UIView
并选择所有边缘:
UIView
接下来,在故事板中将draw(_ rect: CGRect)
设置为final class CrossedView: UIView {
override func draw(_ rect: CGRect) {
let path = UIBezierPath()
path.move(to: .zero)
path.addLine(to: CGPoint(x: frame.width, y: frame.height))
path .move(to: CGPoint(x: 0, y: frame.height))
path.addLine(to: CGPoint(x: frame.width, y: 0))
UIColor.gray.setStroke()
path.stroke()
}
}
,运行。
Class
最后,您得到预期的结果:
CrossedView
那么NSAttributedString不支持“交叉打击”。您必须在UILabel上添加带有交叉打击图标的ImageView。