Guest User

Untitled

a guest
Dec 9th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. let linePath = UIBezierPath()
  2. linePath.moveToPoint(CGPointMake(0, yourLabel.bounds.height))
  3. linePath.addLineToPoint(CGPointMake(yourLabel.bounds.width, 0))
  4.  
  5. let lineLayer = CAShapeLayer()
  6. lineLayer.path = linePath.CGPath
  7. lineLayer.lineWidth = 2
  8. lineLayer.strokeColor = UIColor.lightGrayColor().CGColor
  9. yourLabel.layer.addSublayer(lineLayer)
  10.  
  11. extension UILabel {
  12. /// Strikes through diagonally
  13. /// - Parameters:
  14. /// - offsetPercent: Improve visual appearance or flip line completely by passing a value between 0 and 1
  15. func diagonalStrikeThrough(offsetPercent: CGFloat = 0.1) {
  16. let linePath = UIBezierPath()
  17. linePath.move(to: CGPoint(x: 0, y: bounds.height * (1 - offsetPercent)))
  18. linePath.addLine(to: CGPoint(x: bounds.width, y: bounds.height * offsetPercent))
  19.  
  20. let lineLayer = CAShapeLayer()
  21. lineLayer.path = linePath.cgPath
  22. lineLayer.lineWidth = 2
  23. lineLayer.strokeColor = textColor.cgColor
  24. layer.addSublayer(lineLayer)
  25. }
  26. }
Add Comment
Please, Sign In to add comment