我有一张图片,我用它来构建推文。它由两个圆形矩形组成,左上角有一个 Twitter 图标。重要的是它是可重复的,因为你可以垂直复制中间部分的任何部分,它会是一样的,只是更长。这是我创建的图像:
我的问题是,在代码中,我如何根据 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/