문제

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 ?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top