嗨,我在UIview上創建小費氣球。我的代碼是在UIView上實現的。如何在iOS中製作帶有底部箭頭的提示氣球?
static const CGFloat HEIGHTOFPOPUPTRIANGLE = 20.0f;
static const CGFloat WIDTHOFPOPUPTRIANGLE = 40.0f;
static const CGFloat borderRadius = 8.0f;
static const CGFloat strokeWidth = 3.0f;
CGContextRef context = UIGraphicsGetCurrentContext();
// CGContextTranslateCTM(context, 0.0f, self.bounds.size.height);
// CGContextScaleCTM(context, 1.0f, -1.0f);
CGRect currentFrame = self.bounds;
CGContextSetLineJoin(context, kCGLineJoinRound);
CGContextSetLineWidth(context, strokeWidth);
CGContextSetStrokeColorWithColor(context, [[UIColor redColor] CGColor]);
CGContextSetFillColorWithColor(context, [[UIColor yellowColor] CGColor]);
// Draw and fill the bubble
CGContextBeginPath(context);
CGContextMoveToPoint(context, borderRadius + strokeWidth + 0.5f, strokeWidth + HEIGHTOFPOPUPTRIANGLE + 0.5f);
CGContextAddLineToPoint(context, round(currentFrame.size.width/2.0f - WIDTHOFPOPUPTRIANGLE/2.0f) + 0.5f, HEIGHTOFPOPUPTRIANGLE + strokeWidth + 0.5f);
CGContextAddLineToPoint(context, round(currentFrame.size.width/2.0f) + 0.5f, strokeWidth + 0.5f);
CGContextAddLineToPoint(context, round(currentFrame.size.width/2.0f + WIDTHOFPOPUPTRIANGLE/2.0f) + 0.5f, HEIGHTOFPOPUPTRIANGLE + strokeWidth + 0.5f);
CGContextAddArcToPoint(context, currentFrame.size.width - strokeWidth - 0.5f, strokeWidth + HEIGHTOFPOPUPTRIANGLE + 0.5f, currentFrame.size.width - strokeWidth - 0.5f, currentFrame.size.height - strokeWidth - 0.5f, borderRadius - strokeWidth);
CGContextAddArcToPoint(context, currentFrame.size.width - strokeWidth - 0.5f, currentFrame.size.height - strokeWidth - 0.5f, round(currentFrame.size.width/2.0f + WIDTHOFPOPUPTRIANGLE/2.0f) - strokeWidth + 0.5f, currentFrame.size.height - strokeWidth - 0.5f, borderRadius - strokeWidth);
CGContextAddArcToPoint(context, strokeWidth + 0.5f, currentFrame.size.height - strokeWidth - 0.5f, strokeWidth + 0.5f, HEIGHTOFPOPUPTRIANGLE + strokeWidth + 0.5f, borderRadius - strokeWidth);
CGContextAddArcToPoint(context, strokeWidth + 0.5f, strokeWidth + HEIGHTOFPOPUPTRIANGLE + 0.5f, currentFrame.size.width - strokeWidth - 0.5f, HEIGHTOFPOPUPTRIANGLE + strokeWidth + 0.5f, borderRadius - strokeWidth);
CGContextClosePath(context);
CGContextDrawPath(context, kCGPathFillStroke);
使用此代碼我的小費氣球創造這種
....
,但我想箭頭底部不上頭,請忽略寫在提示氣球UIView的文本。只關注紅色邊框。 SO爲創建底部,所以我上面的兩行註釋掉箭頭....
CGContextTranslateCTM(context, 0.0f, self.bounds.size.height);
CGContextScaleCTM(context, 1.0f, -1.0f);
通過對這個我已經創造尖端氣球與底部箭頭,但問題是在這裏就像文字我的小費熱氣球的UIView旋轉所有內容這樣的形象....
我想與底部箭頭這個技巧氣球但像正確的方式文本等內容寫入。 所以請告訴我任何解決方案,我真的很感謝你。基本上我是按照這個鏈接。
How to draw a "speech bubble" on an iPhone?