簡體   English   中英

在聊天應用程序中拉伸氣泡圖像

[英]Stretching bubble image in Chat app

我正在創建一個聊天應用。 我必須根據文本像其他chatapps一樣拉伸bubble圖像。 我正在使用AutoLayout約束。 包含氣泡增加器的imageview的大小完美。 (我給它加了黃色背景色)。 氣泡圖像沒有被拉伸。

在此輸入圖像描述

我添加了這些約束:

在此輸入圖像描述

為了拉伸圖像我添加了這個:

let myImage =  self.imageNamed("Bubble_Me")
        let new_Image = myImage.stretchableImage(withLeftCapWidth: 15, topCapHeight: 14)
        cell.bubbleImage.image = new_Image

如果有人對此有所了解,請回復。 提前致謝。

首先使用此方法獲取文本的大小。

UIFont *font = [UIFont systemFontOfSize:14.0];
    NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObject:font
                                                                forKey:NSFontAttributeName];
    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:message attributes:attrsDictionary];

    CGRect paragraphRect =
    [attrString boundingRectWithSize:CGSizeMake(tableView.frame.size.width - 20 , CGFLOAT_MAX)
                                 options:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)
                                 context:nil];

獲得文本框架后,從文本框架中獲取高度,並將高度放入泡沫的imageView中。 這一切都完成了將tableViewCell自定義類放入-(void)layoutSubviews method.

你應該做的是在TextView的背景中設置圖像,使其延伸盡可能多的textview

text.backgroundColor =  UIColor(patternImage: UIImage(named:"bg.png")!)

對於此類問題,您應該始終使用“可調整大小的位圖”,更好地稱為9補丁圖像。

試試這個@SNarula

cell.bubbleImage.image = [[UIImage imageNamed:@"Bubble_Me"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 20, 20, 20) resizingMode:UIImageResizingModeStretch];

試試這個:

cell.bubbleImage.image = [[UIImage imageNamed:@"sender.png"] stretchableImageWithLeftCapWidth:2 topCapHeight:2];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM