Its always great to answer your own question... So a whole day i was trying to create that bubble and eventually i ended up creating UIView
with UIImageView
and UITextView
subviews. First thing that helped was using resizableImageWithCapInsets
like this:
switch (self.arrowDirection) {
case BUBBLE_ARROW_DIRECTION_LEFT:
imageForBubble = [[UIImage
imageNamed:@"chatBoxLeftSmall.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(30, 50, 30, 30)];
break;
case BUBBLE_ARROW_DIRECTION_RIGHT:
imageForBubble = [[UIImage
imageNamed:@"chatBoxRightSmall.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(30, 30, 30, 40)];
break;
default:
break;
}
And resizing it using animations like this:
-(void) setSizeForTextView:(UITextView *)textView
{
CGSize newSize = [textView sizeThatFits:CGSizeMake(textView.frame.size.width, MAXFLOAT)];
CGRect newFrame = textView.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, textView.frame.size.width), newSize.height);
if(newFrame.size.height > self.initialTextViewFrame.size.height){
[UIView animateWithDuration:0.1f
animations:^{
[self setFrame:CGRectMake(self.frame.origin.x,
self.frame.origin.y,
kMAX_WIDTH,
newFrame.size.height+kTXT_VIEW_PADDING_BOTTOM)];
[self.bubbleImage setFrame:CGRectMake(self.bubbleImage.frame.origin.x,
self.bubbleImage.frame.origin.y,
self.bubbleImage.frame.size.width,
newFrame.size.height + (kTXT_VIEW_PADDING_BOTTOM - kBUBBLE_IMAGE_PADDING_BOTTOM))];
textView.frame = newFrame;
}
completion:^(BOOL finished){
}];
}else if (newFrame.size.height < self.initialTextViewFrame.size.height){
[UIView animateWithDuration:0.1f
animations:^{
[self setFrame:CGRectMake(self.frame.origin.x,
self.frame.origin.y,
kMAX_WIDTH,
self.initialViewFrame.size.height)];
[self.bubbleImage setFrame:CGRectMake(self.bubbleImage.frame.origin.x,
self.bubbleImage.frame.origin.y,
self.bubbleImage.frame.size.width,
self.initialViewFrame.size.height-kBUBBLE_IMAGE_PADDING_BOTTOM)];
textView.frame = newFrame;
}
completion:^(BOOL finished){
textView.frame = self.initialTextViewFrame;
}];
}
}
If someone will find a better way to do this, please let me know. From i will stick with this one.