Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let linePath = UIBezierPath()
- linePath.moveToPoint(CGPointMake(0, yourLabel.bounds.height))
- linePath.addLineToPoint(CGPointMake(yourLabel.bounds.width, 0))
- let lineLayer = CAShapeLayer()
- lineLayer.path = linePath.CGPath
- lineLayer.lineWidth = 2
- lineLayer.strokeColor = UIColor.lightGrayColor().CGColor
- yourLabel.layer.addSublayer(lineLayer)
- 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)
- }
- }
Add Comment
Please, Sign In to add comment