2013-01-04 83 views
1

繪製形狀,我有以下代碼:在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); 
} 

出於某種原因,它不是畫我想要的形狀。實際上它什麼都沒有吸引。有什麼我做錯了嗎?

+0

你應該明確地調用[super drawRect:rect];在方法結束時。 – Andy

+0

此視圖是否有任何子視圖? – sqreept

回答

0

上面的代碼工作得很好。

我想你正在畫屏幕,因爲我在使用全屏視圖時看到iPhone 5屏幕底部的評論泡泡。

使用小中心視圖時,請看下面的結果。

enter image description here

+1

WHOA,巨大的形象。 – CodaFi

+0

iPhone 5原生分辨率。怪蘋果;) – sqreept