为什么不能显示灰色气泡图像?

时间:2016-05-10 04:14:32

标签: ios swift facebook-chat uibubbletableview

我正在与Swift聊天iOS应用。在ChatLogController中,我在聊天屏幕中添加了两个气泡图像。显示了蓝色气泡图像,但无法显示灰色气泡。我确信我已经在xcassets文件中添加了两个图像。

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()
        }

感谢。

simulator image

1 个答案:

答案 0 :(得分:1)

您使用的图像渲染模式为always template,因此如果您的图片为png,然后设置了imageview的色调,则会更改该png图片的颜色。因此,我认为您为该图像视图添加了灰色色调,使图像变为灰色,如果该图像视图的背景颜色为灰色,则无法区分它们。

希望这会有所帮助:)