这是一个聊天应用,气泡是背景图片,对于文本,我可以用“resizableImageWithCapInsets”拉伸气泡图像,然后在气泡上绘制文本。但问题是当它是一个随机图像时,我如何在气泡上绘制图像,就像它在所附图片中的方式一样?mac上的ios message和imessage都以这种方式显示图像。
问问题
1639 次
2 回答
0
看看BubbleThingie示例应用程序。它会像您的示例图像一样进行图像遮罩和光泽效果。
于 2013-03-17T17:22:18.760 回答
0
如果您的气泡由 UIImageView(它是 UIView 的子类)表示,您可以添加另一个 UIImageView 作为气泡的子视图。你可以使这个子视图的框架等于你的气泡的框架,然后将气泡的 clipsToBounds 属性设置为 YES,这样子视图就被限制在气泡上。
然后将子视图的 contentMode 设置为 UIViewContentModeAspectFill,这会将图像拉伸到气泡的大小。像这样的东西:
//After resizing the bubble to the size you want, to this:
bubbleView.clipsToBounds = YES;
UIImageView *imageView = [[UIImageView alloc] initWithFrame:bubbleView.frame];
imageView.image = theImage;
imageView.contentMode = UIViewContentModeAspectFill;
[bubbleView addSubview:imageView];'
[imageView release];
于 2012-08-01T04:21:30.577 回答