사물을 사용자 정의하려고 시도한 나쁜 경험을 가진 분석가 경고를 수정하고 Xcode 4에서 빌드하는 것을 좋아하지 않습니다. 새 프로젝트에서 다시 사용하지 않을 것입니다. 하지만 아마이 경우에 당신이 원하는 것을 할 것입니다.
그러나 자신의 거품을 상당히 간단하게 만들 수 있습니다. 나는 내가 이걸 가지고 블로그의 저자에게 신용을 줄 수 있었으면 좋겠어,하지만 2 년 전이었고 지금은 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가 시작하는 데 사용 된 위치로 재설정하십시오.
또는 편집 할 때 텍스트와 함께 표시된 코드 (this StackOverflow question 참조)로 만든 풍선 이미지를 표시하는 주소 입력 필드로 UIWebView를 사용할 수 있습니다. 추가 된 주소 삭제를 처리하는 대리자 메서드 shouldChangeCharactersInRange에 대한 처리기를 작성하고 버블이 삭제 작업이 타겟팅하는 항목 인 경우 버블 이미지 만 작성하면됩니다.
이 오래된 질문을 현실로 만들어 주어서 죄송합니다. 하지만 어떻게 구현했는지 코드를 보여 주시겠습니까? 파란 환약을위한 심상 파일이 있는가? –