SNa*_*ula 6 chat stretch uiimage image-resizing ios
我正在创建一个聊天应用.我必须bubble像其他人一样根据文字拉伸图像chatapps.我正在使用AutoLayout约束.包含气泡增加器的imageview的大小完美.(我给它加了黄色背景色).气泡图像没有被拉伸.
我添加了这些约束:
为了拉伸图像我添加了这个:
let myImage = self.imageNamed("Bubble_Me")
let new_Image = myImage.stretchableImage(withLeftCapWidth: 15, topCapHeight: 14)
cell.bubbleImage.image = new_Image
Run Code Online (Sandbox Code Playgroud)
如果有人对此有所了解,请回复.提前致谢.
小智 0
首先使用它来获取文本的大小。
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];
Run Code Online (Sandbox Code Playgroud)
获取文本框架后,获取文本框架的高度并将高度放入气泡的 imageView 中。这一切都在 tableViewCell 自定义类中完成-(void)layoutSubviews method.