我不喜歡Three20曾嘗試過定製事情,修復分析器警告並使其在Xcode 4中生成的不良經歷。在新項目中永遠不會再使用它。但在這種情況下,它可能會做你想要的。
但是,您可以簡單地製作自己的泡泡。我希望我可以讚揚我從中得到這個博客的作者,但是這是兩年前,現在我無法用Google找到它。基本上你選擇一種顏色,畫圓形的端蓋,在它們之間放一個矩形,然後把所需的文字放在頂端。
UIGraphicsBeginImageContext(CGSizeMake(SIDELENGTH, SIDELENGTH));
CGContextRef context = UIGraphicsGetCurrentContext();
// the image should have a white background
[[UIColor clearColor] set];
CGRect myRect = CGRectMake(0.0f, 0.0f, SIDELENGTH, SIDELENGTH);
UIRectFill(myRect);
[self.color set];
// Drawing code
CGSize textSize = [self.text sizeWithFont:[UIFont boldSystemFontOfSize:[UIFont systemFontSize]]];
double capDiameter = textSize.height;
double capRadius = capDiameter/2.0;
double capPadding = capDiameter/4.0;
double textWidth = MAX(capDiameter, textSize.width) ;
CGRect textBounds = CGRectMake(capPadding, 0.0, textWidth, textSize.height);
CGRect badgeBounds = CGRectMake(0.0, 0.0, textWidth + (2.0 * capPadding), textSize.height);
double offsetX = (CGRectGetMaxX(myRect) - CGRectGetMaxX(badgeBounds))/2.0;
double offsetY = (CGRectGetMaxY(myRect) - CGRectGetMaxY(badgeBounds))/2.0;
badgeBounds = CGRectOffset(badgeBounds, offsetX, offsetY);
textBounds = CGRectOffset(textBounds, offsetX, offsetY);
CGContextFillEllipseInRect(context,
CGRectMake(badgeBounds.origin.x, badgeBounds.origin.y, capDiameter, capDiameter));
CGContextFillEllipseInRect(context,
CGRectMake(badgeBounds.origin.x + badgeBounds.size.width - capDiameter, badgeBounds.origin.y,
capDiameter, capDiameter));
CGContextFillRect(context, CGRectMake(badgeBounds.origin.x + capRadius, badgeBounds.origin.y,
badgeBounds.size.width - capDiameter, capDiameter));
if(self.textColor != nil) {
const CGFloat* colors = CGColorGetComponents(self.textColor.CGColor);
CGColorSpaceRef space = CGColorGetColorSpace(self.textColor.CGColor);
CGColorSpaceModel model = CGColorSpaceGetModel(space);
if(model == kCGColorSpaceModelMonochrome)
// monochrome color space has one grayscale value and one alpha
CGContextSetRGBFillColor(context, *(colors + 0), *(colors + 0), *(colors + 0), *(colors + 1));
else
// else a R,G,B,A scheme is assumed.
CGContextSetRGBFillColor(context, *(colors + 0), *(colors + 1), *(colors + 2), *(colors + 3));
} else
// else use plain white
CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f);
[self.text drawInRect:textBounds
withFont:[UIFont boldSystemFontOfSize:[UIFont systemFontSize]]
lineBreakMode:UILineBreakModeClip alignment:UITextAlignmentCenter];
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
您所描述的刪除按鈕的行爲是很簡單太 - 一旦你有一個選擇和接受的平局在插入點的泡沫和改變的UITextField的框架泡發後,開始了比賽。如果您位於UITextField框架的開頭,並且您得到另一個刪除,請刪除泡泡UIImageView,將UITextField框架重置爲UIImageView用於開始的位置。
或者您可以使用UIWebView作爲地址輸入字段,在該地址輸入字段中顯示使用隨文本顯示的代碼(請參閱this StackOverflow question)創建的氣泡圖像。您只需爲委託方法shouldChangeCharactersInRange編寫處理程序來處理刪除添加的地址以及氣泡圖像(如果氣泡是刪除操作所針對的項目)。
對不起提出這個老問題的生活。但是,你能告訴我們你的代碼是如何實現的嗎?你也有藍色藥丸的圖像文件? – 2012-01-25 00:56:55