Note that there are some explanatory texts on larger screens.

plurals
  1. POdrawRect: isn't working
    primarykey
    data
    text
    <p>I want to place some "handles" on a <code>UIView</code> I have on-screen.</p> <p>So, I'm creating more <code>UIView</code>s, one at each corner of the <code>UIView</code>'s frame rectangle, and I simply want to draw a circle that "fills" the rectangle that is the frame of the "handle" <code>UIView</code>.</p> <p>Here's what I mean:</p> <p><b>How I create the "HandleView":</b></p> <pre><code>CGPoint upperLeft = CGPointMake([[self viewToMove] frame].origin.x - 5, [[self viewToMove] frame].origin.y - 5); HandleView *uL = [[HandleView alloc] initWithFrame:CGRectMake(upperLeft.x, upperLeft.y, 10, 10)]; [self setUpperLeftHandle:uL]; [uL release]; [[self view] addSubview:[self upperLeftHandle]]; </code></pre> <p><b>drawRect: for HandleView:</b></p> <pre><code>- (void)drawRect:(CGRect)rect { // Drawing code CGContextRef context = UIGraphicsGetCurrentContext(); [[UIColor orangeColor] set]; CGContextFillEllipseInRect(context, [self frame]); } </code></pre> <p>What I'm getting is just a set of black rectangles where I place the HandleViews. I'm not sure why they're black, but I can change the color by changing the <code>[HandleView backgroundColor]</code> property. I cannot, though, get anything to DRAW on this view. Calling <code>setNeedsDisplay</code> doesn't seem to make any difference.</p> <p>Also, the <code>drawRect:</code> method IS being called, so there's a problem with the code there, probably not anywhere else.</p> <p>It's been a while since I've messed with custom drawing, but I don't remember it being this hard.</p> <p>What am I missing?</p> <p>Thanks!!!</p> <p>Update:</p> <p>Modified code to this:</p> <pre><code>- (id)initWithFrame:(CGRect)frame { if ((self = [super initWithFrame:frame])) { // Initialization code [self setBackgroundColor:[UIColor clearColor]]; } return self; } - (void)drawRect:(CGRect)rect { // Drawing code CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetRGBFillColor(context, 100, 100, 100, 1.0); CGContextFillEllipseInRect(context, rect); } </code></pre> <p>Now, I see the circle, but only where it overlays another view. Where it's just sitting on top of the "background" UIView, I get nothing I can see. Also, even though the color is (100, 100, 100), it shows up white/light-light-gray.</p> <p>What's the deal?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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