use*_*897 1 label uilabel strikethrough
我想用 UILabel 文本制作这样的效果
我怎样才能做到这一点?我在网上没有找到任何帮助;我刚刚找到了有关水平线的帮助
PS:抱歉我的英语不好,我是意大利人:)
enoktate 的答案更新为Swift 4.2,并作为扩展编写
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)
}
}
Run Code Online (Sandbox Code Playgroud)