我正在创建一个聊天应用。我必须像其他bubble
一样根据文字拉伸chatapps
图片。我正在使用AutoLayout约束。包含气泡增加器的imageview的大小完美。 (我给它加了黄色背景色)。气泡图像没有被拉伸。
我添加了这些约束:
对于拉伸图像,我添加了这个:
let myImage = self.imageNamed("Bubble_Me")
let new_Image = myImage.stretchableImage(withLeftCapWidth: 15, topCapHeight: 14)
cell.bubbleImage.image = new_Image
如果有人对此有所了解,请回复。 提前致谢。
答案 0 :(得分:0)
首先使用此功能获取文本的大小。
kill -9 <pid>
获得文本框后,从文本框中获取高度,并将高度放入泡泡的imageView中。这一切都在tableViewCell自定义类中完成了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];
答案 1 :(得分:0)
你应该做的是在TextView的背景中设置图像,使其延伸尽可能多的文本视图
text.backgroundColor = UIColor(patternImage: UIImage(named:"bg.png")!)
您应该始终使用&#34;可调整大小的位图&#34;对于此类问题,更好地称为9补丁图像。
答案 2 :(得分:0)
试试@SNarula
cell.bubbleImage.image = [[UIImage imageNamed:@"Bubble_Me"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 20, 20, 20) resizingMode:UIImageResizingModeStretch];
答案 3 :(得分:0)
试试这个:
cell.bubbleImage.image = [[UIImage imageNamed:@"sender.png"] stretchableImageWithLeftCapWidth:2 topCapHeight:2];