Guest User

Untitled

a guest
Apr 22nd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. // MARK: Frameworks
  2.  
  3. import UIKit
  4.  
  5. // MARK: ViewController
  6.  
  7. class ShapeViewController: UIViewController {
  8.  
  9. // MARK: Outlets
  10.  
  11. @IBOutlet var shapeView: UIView!
  12. @IBOutlet var buttonView: UIView!
  13. @IBOutlet var nextButton: UIButton!
  14. @IBOutlet var previousButton: UIButton!
  15.  
  16. // MARK: Variables
  17.  
  18. var shapes: [CAShapeLayer] = []
  19. var index: Int = 0 {
  20. didSet {
  21. let currentShape = shapes[index]
  22. shapeView.layer.sublayers?.removeAll()
  23. shapeView.layer.addSublayer(currentShape)
  24. }
  25. }
  26.  
  27. // MARK: View Methods
  28.  
  29. override func viewDidAppear(_ animated: Bool) {
  30. super.viewDidAppear(animated)
  31.  
  32. shapes = [shapeCreator(bezierPath: UIBezierPath(homeIn: shapeView.bounds)),
  33. shapeCreator(bezierPath: UIBezierPath(addIn: shapeView.bounds)),
  34. shapeCreator(bezierPath: UIBezierPath(profileIn: shapeView.bounds)),
  35. shapeCreator(bezierPath: UIBezierPath(searchIn: shapeView.bounds))]
  36.  
  37. index = 0
  38. }
  39.  
  40. // MARK: Helper Methods
  41.  
  42. private func shapeCreator(bezierPath: UIBezierPath) -> CAShapeLayer {
  43. let shape = CAShapeLayer()
  44. shape.frame = bezierPath.bounds
  45. shape.path = bezierPath.cgPath
  46. shape.fillColor = UIColor.clear.cgColor
  47. shape.strokeColor = UIColor.red.cgColor
  48. shape.lineWidth = 2
  49. return shape
  50. }
  51.  
  52. // MARK: Action Methods
  53.  
  54. @IBAction func previous(_ sender: Any?) {
  55. if index == 0 {
  56. index = (shapes.count - 1)
  57. } else {
  58. index = index - 1
  59. }
  60. }
  61.  
  62. @IBAction func next(_ sender: Any?) {
  63. if index == (shapes.count - 1) {
  64. index = 0
  65. } else {
  66. index = index + 1
  67. }
  68. }
  69. }
Add Comment
Please, Sign In to add comment