[英]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.