gpt4 book ai didi

iPhone:如何扩展可重复的 UIImage?

转载 作者:可可西里 更新时间:2023-11-01 05:07:02 27 4
gpt4 key购买 nike

我有一张图片,我用它来构建推文。它由两个圆形矩形组成,左上角有一个 Twitter 图标。重要的是它是可重复的,因为你可以垂直复制中间部分的任何部分,它会是一样的,只是更长。这是我创建的图像:

Tweet Frame

我的问题是,在代码中,我如何根据 UITextView 中的行数来扩展(或收缩)它?像这样获得尺寸:

float requiredHeight = lines * 14;

我知道这是可能的,因为苹果用他们的 SMS 应用程序做到了:)


更新:这是执行此操作的完整代码:

UIImage *loadImage = [UIImage imageNamed:@"TwitPost.png"];
float w2 = loadImage.size.width/2;
float h2 = loadImage.size.height/2;
// I have now reduced the image size so the height must be offset a little (otherwise it stretches the bird!):
loadImage = [loadImage stretchableImageWithLeftCapWidth:w2 topCapHeight:h2+15];
imageView.image = loadImage;

感谢您的回答。

最佳答案

通过使用

- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCapHeight

将 leftCapWidth 和 topCapHeight 设置为图像宽度和高度的一半。您可以通过更改其边界/框架在 UIImageView 中拉伸(stretch)此图像。

关于iPhone:如何扩展可重复的 UIImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6857217/

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