Search code examples
iosswiftfacebook-chatuibubbletableview

Why can't the gray bubble image be shown?


I am doing a chat iOS app with Swift. In ChatLogController, I added two bubble images to the chat screen.The blue bubble image is shown, but the gray bubble can't be shown. I am sure that I have added two images to the xcassets file.

static let grayBubbleImage = UIImage(named:"bubble_gray")!.resizableImageWithCapInsets(UIEdgeInsetsMake(22,26,22,26)).imageWithRenderingMode(.AlwaysTemplate)
static let blueBubbleImage = UIImage(named:"bubble_blue")!.resizableImageWithCapInsets(UIEdgeInsetsMake(22,26,22,26)).imageWithRenderingMode(.AlwaysTemplate)

let bubbleImageView:UIImageView =
{
    let imageView = UIImageView()
    imageView.image = ChatLogMessageCell.grayBubbleImage
    imageView.tintColor = UIColor(white: 0.90, alpha: 1)
    return imageView
}()
 if message.isSender!.boolValue
    {
        cell.messageTextView.frame = CGRectMake(48 + 8, 0, estimatedFrame.width + 16, estimatedFrame.height + 20)
        cell.textBubbleView.frame = CGRectMake(48 - 10, -4, estimatedFrame.width + 16 + 8 + 16, estimatedFrame.height + 20 + 6)
        cell.profileImageView.hidden = false
       // cell.textBubbleView.backgroundColor = UIColor(white: 0.95, alpha: 1)
        cell.bubbleImageView.image = ChatLogMessageCell.grayBubbleImage
        cell.bubbleImageView.tintColor = UIColor(white: 0.95, alpha: 1)
        cell.messageTextView.textColor = UIColor.blackColor()

}

else
    {
        cell.messageTextView.frame = CGRectMake(view.frame.width - estimatedFrame.width - 16 - 16,0, estimatedFrame.width + 16, estimatedFrame.height+20)
        cell.textBubbleView.frame = CGRectMake(view.frame.width - estimatedFrame.width - 16 - 16 - 8, 0, estimatedFrame.width + 16 + 8, estimatedFrame.height+20)
        cell.profileImageView.hidden = true
       // cell.textBubbleView.backgroundColor = UIColor(red: 0, green: 137/255, blue: 249/255, alpha: 1)
        cell.bubbleImageView.image = ChatLogMessageCell.blueBubbleImage
        cell.bubbleImageView.tintColor = UIColor(red: 0, green: 137/255, blue: 249/255, alpha: 1)
        cell.messageTextView.textColor = UIColor.whiteColor()
        }

Thanks.

simulator image


Solution

  • You are using image rendering mode is always template so if your image is png and then you set imageview's tint color then it change the color of that png image. So, I think you are giving gray tint color to that image view so that image becoming gray and if your background color of that imageview is gray then you can't differentiate between them.

    Hope this will help :)