More practice with Core Graphics
Draw a line on a view that has the following array of coordinates:
(-1,0)
(-5,2)
(4,-2)
(10,-1)
(-2,-2)
(-1,-1)
(10,-5)
(5,5)
(5,6)
(-6,1)
Requirements:
-
Let's start by considering the center of your
UIView
the "origin" of the graph. -
Make sure all points are on screen.
-
Make sure that your line is drawn without turning back on itself (like a graph!) and also as a rule we'll draw coordinates that have the same X value from lower Y value to higher Y value.
-
Make the color and width of the line able to be changed by the user of your view class without them having to inspect the implementation code in detail.
-
Make it possible for the user to add more lines to the view using an
NSArray
of lines. -
Add a graph background gradient. Make the colors also easily changed by the user. Ideally, make them updateable from the Storyboard Attributes Inspector and the gradient render in your storyboard.
Here is what your output should look like when you are finished:
If you need a reminder on how to make objects IBInspectable
and views IB_DESIGNABLE
, check out an article.
-
Helper methods might be useful to create to save you some time with repetitive tasks!
-
Don't forget to release references you create yourself!