gpt4 book ai didi

ios - 在 iMessage 等气泡图像背景上绘制随机图像

转载 作者:行者123 更新时间:2023-12-01 16:56:01 24 4
gpt4 key购买 nike

这是一个聊天应用,气泡是背景图片,对于文本,我可以用“resizableImageWithCapInsets”拉伸(stretch)气泡图像,然后在气泡上绘制文本。
但问题是当它是一个随机图像时,我如何在气泡上绘制图像,就像它在附加图片中的方式一样? mac上的ios message和imessage都以这种方式显示图像。

http://i.stack.imgur.com/sgJhv.png

最佳答案

如果您的气泡由 UIImageView(它是 UIView 的子类)表示,您可以添加另一个 UIImageView 作为气泡的 subview 。你可以使这个 subview 的框架等于你的气泡的框架,然后将气泡的 clipsToBounds 属性设置为 YES,这样 subview 就被限制在气泡上。

然后将 subview 的 contentMode 设置为 UIViewContentModeAspectFill,这会将图像拉伸(stretch)到气泡的大小。像这样的东西:

//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];

关于ios - 在 iMessage 等气泡图像背景上绘制随机图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11752073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com