我想了解resizableImageWithCapInsets是如何工作的,所以我找到了这张图片
图像的大小是57x51,所以我创建了这样的图像
image = [[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"PopoverViewBlackBackgroundArrowDown" ofType:@"png"]]
resizableImageWithCapInsets:UIEdgeInsetsMake(25.0, 28.0, 25.0, 28.0)];
图像视图如下所示
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:image];
backgroundImageView.frame = CGRectMake(0.0f, 0.0f, 210.0f, 110.0f);
[self.view addSubview:backgroundImageView];
但结果如下
它看起来不像传统的UIPopoverController。箭头也在调整大小。
你知道为什么吗?
谢谢你的回答。
发布于 2012-06-08 12:56:58
我认为您的问题是边缘插入设置不正确。您应该尝试做的是移动左侧和右侧插图,使其位于箭头区域的外侧。
此时,您已经在图像的中心将可伸展区域的宽度设置为0,因此它在一个点上拉伸了中间的箭头。顶部和底部的插图看起来都不错,所以你的目标是这样的:
resizableImageWithCapInsets:UIEdgeInsetsMake(25.0, 10.0, 25.0, 47.0)];
也就是说,在图像的左边和右边有10像素的边距。
希望这能有所帮助
https://stackoverflow.com/questions/10949123
复制