Guest User

Untitled

a guest
Jan 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. let font = UIFont.systemFont(ofSize: 12)
  2. let attributes = [
  3. NSAttributedString.Key.font: UIConstants.CaptionFont,
  4. NSAttributedString.Key.foregroundColor: UIColor.accent
  5. ]
  6.  
  7. for path in pathsForIndicators {
  8. let cgPath = path.cgPath
  9. let layer = CATextLayer()
  10. layer.frame = CGRect(x: cgPath.boundingBox.midX + offset + 22,
  11. y: cgPath.boundingBox.midX + 10, width: 40, height: 40)
  12. layer.position = CGPoint(x: cgPath.boundingBox.midX + offset + 22,
  13. y: cgPath.boundingBox.midY + 10)
  14. layer.font = font
  15. let value = 0 // TODO
  16. let title = String(describing: value)
  17. let attributedString = NSAttributedString(string: title, attributes: attributes)
  18. layer.string = attributedString
  19. layer.isWrapped = false
  20. layer.alignmentMode = CATextLayerAlignmentMode.center
  21. layer.foregroundColor = indicatorColor.cgColor
  22. layer.shouldRasterize = true
  23. layer.needsDisplayOnBoundsChange = false
  24. layer.needsDisplay()
  25. layer.displayIfNeeded()
  26. textLayer.addSublayer(layer)
  27. }
  28. textLayer.backgroundColor = UIColor.clear.cgColor
  29. textLayer.bounds = bounds
  30. textLayer.position = centerPoint
  31. layer.addSublayer(textLayer)
Add Comment
Please, Sign In to add comment