2 xinyoulingxi1 tong xinyoulingxi1_tong 于 2013.01.05 09:43 提问

iphone中drawRect画图形

我的代码如下:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGFloat commentHeight = 0;


        CGSize commentSize = [self.highlightItem_.comment sizeWithFont:[UIFont fontWithName:kProximaNova size:18] constrainedToSize:CGSizeMake(rect.size.width, CGFLOAT_MAX) lineBreakMode:NSLineBreakByWordWrapping];
        commentHeight = commentSize.height + 50;

        CGContextSetRGBStrokeColor(context, 68/255.f, 68/255.f, 68/255.f, 1.0);
        CGContextSetRGBFillColor(context, 68/255.f, 68/255.f, 68/255.f, 1.0);
        CGContextSetLineJoin(context, kCGLineCapSquare);
        CGContextSetLineWidth(context, 1.0);

        CGMutablePathRef pathRef = CGPathCreateMutable();

        CGPathMoveToPoint(pathRef, NULL, 0, rect.size.height - commentHeight);
        CGPathAddLineToPoint(pathRef, NULL, 20, rect.size.height - commentHeight);
        CGPathAddLineToPoint(pathRef, NULL, 25, rect.size.height - commentHeight - 10);
        CGPathAddLineToPoint(pathRef, NULL, 30, rect.size.height - commentHeight);
        CGPathAddLineToPoint(pathRef, NULL, rect.size.width, rect.size.height - commentHeight);
        CGPathAddLineToPoint(pathRef, NULL, rect.size.width, rect.size.height);
        CGPathAddLineToPoint(pathRef, NULL, 0, rect.size.height);
        CGPathCloseSubpath(pathRef);

        CGContextAddPath(context, pathRef);
        //CGContextFillPath(context);
        CGContextDrawPath(context, kCGPathFill);


        CGPathRelease(pathRef);
}

但是没有画出预期的图片,不知道为什么?请高手指教,谢谢

1个回答

wangyaninglm
wangyaninglm   Ds   Rxr 2015.01.13 22:18

可以学习一下,这个重绘的机制:
http://blog.csdn.net/fww330666557/article/details/8647608

Csdn user default icon
上传中...
上传图片
插入图片