UILabel带有对角删除线的文本 [英] UILabel's text with diagonal strikethrough line
本文介绍了UILabel带有对角删除线的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用UILabel文字制作这样的效果
I would like to make an effect like this, with UILabel text
我该怎么做?我在网上找不到任何帮助;我刚刚找到了关于水平线的帮助
how can I do that? I didn't find any help on web; I just found help with horizontal line
PS:对不起,我的英语不好,我是意大利人:)
PS: sorry for my bad english, I'm italian :)
推荐答案
enoktate的答案已更新为 Swift 4.2 ,并作为扩展名写成
enoktate's answer updated to Swift 4.2, and written as an extension
extension UILabel {
/// Strikes through diagonally
/// - Parameters:
/// - offsetPercent: Improve visual appearance or flip line completely by passing a value between 0 and 1
func diagonalStrikeThrough(offsetPercent: CGFloat = 0.1) {
let linePath = UIBezierPath()
linePath.move(to: CGPoint(x: 0, y: bounds.height * (1 - offsetPercent)))
linePath.addLine(to: CGPoint(x: bounds.width, y: bounds.height * offsetPercent))
let lineLayer = CAShapeLayer()
lineLayer.path = linePath.cgPath
lineLayer.lineWidth = 2
lineLayer.strokeColor = textColor.cgColor
layer.addSublayer(lineLayer)
}
}
这篇关于UILabel带有对角删除线的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文