Domanda

All,

i have this piece of code :

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
    CGContextFillRect(context, CGRectMake(0, 440, 320, 30));

and i call it like this :

_rectangeView = [[PopUpRectangle alloc] initWithFrame:CGRectMake(0, 538, 320, 30)];

but its BLACK!

anyone advice why this is ?

È stato utile?

Soluzione

Change your colouring rect like this...

CGContextFillRect(context, CGRectMake(0, 0, 320, 30));

Use 0, 0 as the origins not 0, 440.

That should work.

Inside drawRect you are dealing in the vector space of the view itself not its superview. So 0, 0 is the top left of your rectangleView.

Altri suggerimenti

Your _rectangeView height is just 30 points but the context fill rect bounds y value is 440.0; exceeds the bounds of the view. Try changing the y value to 0 and you will see the color.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top