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

标签 iphone objective-c ios uiimageview uiimage

我有一张图片,我用它来构建推文。它由两个圆形矩形组成,左上角有一个 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/

相关文章:

ios - 如何模态呈现 ViewController,然后在 ViewController 被关闭后运行回调函数/ block ,没有委托(delegate)?

ios - 如何在处理多个任务时跟踪进度和进度 View 的增量计数?

iphone - 从 NSMutableArray iPhone SDK 中删除多个对象时出现问题

iOS : What is the need of register cell before dequeuing in UITableView?

iphone - 为什么我不能使用此代码创建文件夹?

iphone - UIImagePicker Controller : how to take >1 photo?

ios - 如何在安装应用程序后不添加今天的小部件

c++ - Objective-C 如何使用 vector 对?

ios - 指向一个的两个对象

ios - 如何在设置启用 False 时更改 TabBarItem 的颜色