我正在看一些WWDC视频,他们谈论使用UIImageView来拉伸你的图像,不会产生任何额外的内存。他们的例子是使用一个小文本泡泡,就像您在Music应用程序中长按tableViewCell时所获得的泡泡一样。然后他们会谈论如何将它分成3片,左边,右边和中间,因为中间部分底部有一个小三角形,指向您长时间按下的tableViewCell。有人可以解释某人如何做这件事,因为他们没有在他们的例子中提供任何代码?伪代码很好。综观文档,我的猜测是:UIImageView autoresizingmask,UIImage stretchableImageWithLeftCapWidth
从图形编辑器创建的最小尺寸三个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占据整个屏幕,因为这是你想要的图像扩大到?