我正在观看一些WWDC视频,他们谈论使用UIImageView来拉伸你的图像而不会产生任何额外的记忆。他们的例子是使用一个小文本泡泡,就像你在音乐应用程序中长按tableViewCell时得到的那个。然后他们讨论如何将它分成3个切片,左,右和中心,因为中心部分底部有一个小三角形,指向你长按的tableViewCell。有人可以解释某人是如何做到的,因为他们没有在他们的例子中提供任何代码吗?伪代码很好。看一下文档,我的猜测是:
从图形编辑器中创建三个最小尺寸的UIImages:
UIImage *leftImage = [UIImage imageNamed:@"left.png"];
UIImage *rightImage = [UIImage imageNamed:@"right.png"];
UIImage *centerImage = [UIImage imageNamed:@"center.png"];
leftImage = [leftImage stretchableImageWithLeftCapWidth:0 topCapHeight:0];
rightImage = [rightImage stretchableImageWithLeftCapWidth:0 topCapHeight:0];
centerImage = [centerImage stretchableImageWithLeftCapWidth:0 topCapHeight:0];
UIImageView *leftImgView = [[UIImageView alloc] initWithImage:leftImage];
leftImgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIImageView *rightImgView = [[UIImageView alloc] initWithImage:rightImage];
leftImgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIImageView *centerImgView = [[UIImageView alloc] initWithImage:centerImage];
leftImgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
// do I just add them all to the subview of self.view? Do I need to set their frames somewhere? If so, how do I know where they go since it's 3 slices making up an image.
// release memory
我对此主题的相关问题是,您将如何在IB中执行此操作。就像你让3个imageViews占据整个屏幕一样,因为那是你想要的图像扩展到什么?