Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Please reconsider what you are doing there:</p> <ol> <li>In line 4 of your loop, you <code>alloc</code> an instance of <code>GetColor</code> &mdash; which you never use again. Ask yourself: Does that make any sense from a design point of view?</li> <li>In that same line, if you don't violate Cocoa's naming-conventions, you create a UIColor that is never released...</li> <li>Then in line 8 you <em>release the class-object</em> of <code>DrawLine</code> (ditto that for the next line and the <code>GetColor</code>-class). <strong>This is terribly, horribly wrong!</strong></li> </ol> <p>Please visit the <a href="http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html" rel="nofollow">Memory Management Programming Guide</a> at the iOS Dev-Center and read the first two sections (again)!</p> <p>Besides that, re-evaluate your design:</p> <ul> <li>Should <code>GetColor</code> really be a class, so that you create instances? Wouldn't a simple helper-function for color interpolation make more sense in this context?</li> <li>If it should be a class, why not create just one instance of it <em>outside of the loop</em> and simply query it repeatedly for the colors?</li> <li>Do you really need a subclass of UIView to draw a single straight, solid, single-colored line? If the lines need not be updated, you should (as Richard and nacho4d suggested) draw all of them in one object (e.g. by a custom UIView or by a delegate of CALayer implementing the <code>drawLayer:inContext:</code> method). If you need to update those lines later, you could simply (ab)use CALayer...</li> </ul> <p>In the latter case, your problem then becomes:</p> <ol> <li>Calculate your random coordinates.</li> <li>Calculate your color.</li> <li>Create an <em>opaque</em> CALayer with<br> a) that color as its backgroundColor,<br> b) a width of 20 * sqrt(2),<br> c) a height of whatever-you-want-to-be-the-width-of-that-line,<br> d) your point as its origin and<br> e) a <code>rotation</code> of 45. </li> <li>Add that layer as a sublayer to <code>self.view</code>'s layer.</li> </ol> <p>Cheers<br> Daniel</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload