2011-12-09 6 views
1

私が望む形を描くために石英を得ることに若干の問題があります。基本的に私はそうのような形状のためつもりだ:三角形のIOS石英泡

bubble view

私は、丸みを帯びた泡を得ることができますが、私はそれがうまくいかない三角形に追加しようとしたとき。ここで私は通常得るものです:お時間を

enter image description here

感謝。

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGRect currentFrame = self.bounds; 

CGContextSetLineJoin(context, kCGLineJoinRound); 
CGContextSetLineWidth(context, self.BorderWidth); 
CGContextSetStrokeColorWithColor(context, self.BorderColor.CGColor); 
CGContextSetFillColorWithColor(context, self.FillColor.CGColor); 


float pad = BorderWidth + 0.5f; 
float width = currentFrame.size.width - BorderWidth - 0.5f; 
float height = currentFrame.size.height - BorderWidth - 0.5f; 
float rounding = BorderRadius - BorderWidth; 

CGContextMoveToPoint(context,pad + TriangleSize.width, pad); 

//top 
CGContextAddArcToPoint(context, 
         width, 
         pad, 
         width, 
         height, 
         rounding); 
//right 
CGContextAddArcToPoint(context, 
         width, 
         height, 
         round(width/2.0f), 
         height, 
         rounding); 
//bottom 
CGContextAddArcToPoint(context, 
         TriangleSize.width + pad, 
         height, 
         pad, 
         pad , 
         rounding); 

//left 
CGContextAddArcToPoint(context, 
         TriangleSize.width, 
         pad + TriangleSize.height*3, 
         width, 
         pad, 
         0); 

CGContextAddLineToPoint(context,-TriangleSize.width - pad,TriangleSize.height); 
CGContextAddLineToPoint(context,pad + TriangleSize.width, pad + TriangleSize.height); 

CGContextAddArcToPoint(context, 
         pad + TriangleSize.width, 
         pad - TriangleSize.height, 
         width, 
         height, 
         rounding); 

CGContextClosePath(context); 
CGContextDrawPath(context, kCGPathFillStroke); 

答えて

2

私がする必要があるのは、それを理解するための質問を投稿することでした。 :)とにかく、ここで誰もが道を、この後に見つかった場合、私はそれが動作を取得するために使用するコードです:

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGRect currentFrame = self.bounds; 

CGContextSetLineJoin(context, kCGLineJoinRound); 
CGContextSetLineWidth(context, self.BorderWidth); 
CGContextSetStrokeColorWithColor(context, self.BorderColor.CGColor); 
CGContextSetFillColorWithColor(context, self.FillColor.CGColor); 


float pad = BorderWidth + 0.5f; 
float width = currentFrame.size.width - BorderWidth - 0.5f; 
float height = currentFrame.size.height - BorderWidth - 0.5f; 
float rounding = BorderRadius - BorderWidth; 
float pos = (height/3); //height/2 //setting this to a third as I want the arrow to be a bit higher than the middle 

CGContextMoveToPoint(context,pad*3 + TriangleSize.width, pad); 
//top 
CGContextAddArcToPoint(context, 
         width, 
         pad, 
         width, 
         height, 
         rounding); 
//right 
CGContextAddArcToPoint(context, 
         width, 
         height, 
         round(width/2.0f), 
         height, 
         rounding); 
//bottom 
CGContextAddArcToPoint(context, 
         pad + TriangleSize.width, 
         height, 
         pad, 
         pad , 
         rounding); 

CGContextAddLineToPoint(context, TriangleSize.width,pos + TriangleSize.height); 
CGContextAddLineToPoint(context, 0,pos); 
CGContextAddLineToPoint(context, TriangleSize.width,pos - TriangleSize.height); 
//left 
CGContextAddArcToPoint(context, 
         pad + TriangleSize.width, 
         pad, 
         width, 
         pad, 
         rounding); 


CGContextClosePath(context); 
CGContextDrawPath(context, kCGPathFillStroke); 

// Draw a clipping path for the fill 
CGContextBeginPath(context); 
CGContextMoveToPoint(context,pad*3 + TriangleSize.width, pad); 
CGContextAddArcToPoint(context, width, pad, width, height, rounding); 
CGContextAddArcToPoint(context, width, height, round(width/2.0f), height,rounding); 
CGContextAddArcToPoint(context, pad + TriangleSize.width,height, pad, pad, rounding); 
CGContextAddLineToPoint(context, TriangleSize.width,pos + TriangleSize.height); 
CGContextAddLineToPoint(context, 0,pos); 
CGContextAddLineToPoint(context, TriangleSize.width,pos - TriangleSize.height); 
CGContextAddArcToPoint(context, pad + TriangleSize.width,pad,width, pad, rounding); 

CGContextClosePath(context); 
CGContextClip(context); 
+0

あなたがboarderwidth、boarderradius三角形サイズ – Jarod

+0

のために何を設定している。この参照:https://github.comを/daltoniam/GPLib-iOS/blob/master/GPLib/Views/GPBubbleView.mですが、BorderRadius = 8を使用しています。 BorderWidth = 0.5; TriangleSize = CGSizeMake(8,8); – daltoniam