Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 KB | None | 0 0
  1. import UIKit
  2.  
  3. class addShape: UIView {
  4.  
  5.  
  6.  
  7. let context = UIGraphicsGetCurrentContext();
  8.  
  9. override func drawRect(rect: CGRect) {
  10.  
  11.  
  12. CGContextSetLineWidth(context, 3.0)
  13. //CGContextSetStrokeColorWithColor(context, UIColor.purpleColor().CGColor)
  14.  
  15.  
  16.  
  17.  
  18. CGContextStrokeEllipseInRect(context, rect)
  19. UIColor.redColor().set()
  20.  
  21. //Actually draw the path
  22. CGContextStrokePath(context)
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. }
  30.  
  31. override func drawRect(rect: CGRect) {
  32. ////UTUBE
  33. UIGraphicsBeginImageContextWithOptions(CGSize(width: 512, height: 512), false, 0)
  34.  
  35.  
  36. // Define the center point of the view where you’ll rotate the arc around
  37. let center = CGPoint(x:bounds.width/2, y: bounds.height/2)
  38.  
  39. // Calculate the radius based on the max dimension of the view.
  40. let radius: CGFloat = max(bounds.width, bounds.height)
  41.  
  42. // Define the thickness of the arc.
  43. let arcWidth: CGFloat = 115
  44.  
  45.  
  46. /////FIRST Shape
  47. // Define the start and end angles for the arc.
  48. let startAngle: CGFloat = 2 * π
  49. let endAngle: CGFloat = π / 4
  50.  
  51. // Create a path based on the center point, radius, and angles you just defined.
  52. var path = UIBezierPath(arcCenter: center,
  53. radius: radius/2 - arcWidth/2,
  54. startAngle: startAngle,
  55. endAngle: endAngle,
  56. clockwise: true)
  57.  
  58. // Set the line width and color before finally stroking the path.
  59. path.lineWidth = arcWidth
  60. counterColor.setStroke()
  61. path.stroke()
  62.  
  63.  
  64. // Second Shape
  65. let startAngle2: CGFloat = π / 4
  66. let endAngle2: CGFloat = π / 2
  67.  
  68. // Create a path based on the center point, radius, and angles you just defined.
  69. path = UIBezierPath(arcCenter: center,
  70. radius: radius/2 - arcWidth/2,
  71. startAngle: startAngle2,
  72. endAngle: endAngle2,
  73. clockwise: true)
  74.  
  75. path.lineWidth = arcWidth
  76. UIColor.greenColor().setStroke()
  77. path.stroke()
  78.  
  79.  
  80. // 3rd Shape
  81. let startAngle3: CGFloat = π / 2
  82. let endAngle3: CGFloat = 3 * π / 4
  83.  
  84. // Create a path based on the center point, radius, and angles you just defined.
  85. path = UIBezierPath(arcCenter: center,
  86. radius: radius/2 - arcWidth/2,
  87. startAngle: startAngle3,
  88. endAngle: endAngle3,
  89. clockwise: true)
  90.  
  91. path.lineWidth = arcWidth
  92. UIColor.blueColor().setStroke()
  93. path.stroke()
  94.  
  95. // 4th Shape
  96. let startAngle4: CGFloat = 3 * π / 4
  97. let endAngle4: CGFloat = π
  98.  
  99. // Create a path based on the center point, radius, and angles you just defined.
  100. path = UIBezierPath(arcCenter: center,
  101. radius: radius/2 - arcWidth/2,
  102. startAngle: startAngle4,
  103. endAngle: endAngle4,
  104. clockwise: true)
  105.  
  106. path.lineWidth = arcWidth
  107. UIColor.redColor().setStroke()
  108. path.stroke()
  109.  
  110. // 5th Shape
  111. let startAngle5: CGFloat = π
  112. let endAngle5: CGFloat = 5 * π / 4
  113.  
  114. // Create a path based on the center point, radius, and angles you just defined.
  115. path = UIBezierPath(arcCenter: center,
  116. radius: radius/2 - arcWidth/2,
  117. startAngle: startAngle5,
  118. endAngle: endAngle5,
  119. clockwise: true)
  120.  
  121. path.lineWidth = arcWidth
  122. UIColor.yellowColor().setStroke()
  123. path.stroke()
  124.  
  125. // 6th Shape
  126. let startAngle6: CGFloat = 5 * π / 4
  127. let endAngle6: CGFloat = 3 * π / 2
  128.  
  129. // Create a path based on the center point, radius, and angles you just defined.
  130. path = UIBezierPath(arcCenter: center,
  131. radius: radius/2 - arcWidth/2,
  132. startAngle: startAngle6,
  133. endAngle: endAngle6,
  134. clockwise: true)
  135.  
  136. path.lineWidth = arcWidth
  137. UIColor.grayColor().setStroke()
  138. path.stroke()
  139.  
  140. // 7th Shape
  141. let startAngle7: CGFloat = 3 * π / 2
  142. let endAngle7: CGFloat = 7 * π / 4
  143.  
  144. // Create a path based on the center point, radius, and angles you just defined.
  145. path = UIBezierPath(arcCenter: center,
  146. radius: radius/2 - arcWidth/2,
  147. startAngle: startAngle7,
  148. endAngle: endAngle7,
  149. clockwise: true)
  150.  
  151. path.lineWidth = arcWidth
  152. UIColor.purpleColor().setStroke()
  153. path.stroke()
  154.  
  155. // 8th Shape
  156. let startAngle8: CGFloat = 7 * π / 4
  157. let endAngle8: CGFloat = 2 * π
  158.  
  159. // Create a path based on the center point, radius, and angles you just defined.
  160. path = UIBezierPath(arcCenter: center,
  161. radius: radius/2 - arcWidth/2,
  162. startAngle: startAngle8,
  163. endAngle: endAngle8,
  164. clockwise: true)
  165.  
  166. path.lineWidth = arcWidth
  167. UIColor.lightGrayColor().setStroke()
  168. path.stroke()
  169.  
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement