Simple drawing with Quartz - Core Graphics

大城市里の小女人 提交于 2019-12-25 06:41:05

问题


I want to draw a rectangle with the top-left corner rounded with 3 sub-spaces in it. Something like this:

 _______
|_|_____|
|       |
|_______|

But for some reason I cannot get the inner two lines drawn.

- (void) drawRect:(CGRect)rect{
CGContextRef context = UIGraphicsGetCurrentContext();
float cornerRadius = 25.0;
float w = self.bounds.size.width;
float h = self.bounds.size.height;
CGContextMoveToPoint(context, cornerRadius, 0);
CGContextAddQuadCurveToPoint(context, 0, 0, 0, cornerRadius);
CGContextAddLineToPoint(context, 0, h);
CGContextAddLineToPoint(context, w, h);
CGContextAddLineToPoint(context, w, 0);
CGContextAddLineToPoint(context, cornerRadius, 0);

//drawing settings
CGContextSetLineWidth(context, 0.5);
CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetFillColorWithColor(context, [UIColor white].CGColor); 

//draw rectangle
CGContextDrawPath(context, kCGPathFillStroke);

//draw title/label partition
CGContextMoveToPoint(context, TITLE_HEIGHT, 0);
CGContextAddLineToPoint(context, TITLE_HEIGHT, TITLE_HEIGHT);
CGContextStrokePath(context);

//draw title/content partition
CGContextMoveToPoint(context, 0, TITLE_HEIGHT);
CGContextAddLineToPoint(context, self.bounds.size.width, TITLE_HEIGHT);
CGContextStrokePath(context);
}

I wonder what am I mistaking here... ;(

Thanks in advance


回答1:


Try to comment out the CGContextSetFillColorWithColor line for a while - maybe the rectangle is overlapping those lines?



来源:https://stackoverflow.com/questions/4119268/simple-drawing-with-quartz-core-graphics

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!