我想在UITableViewCell
的背面设置拉伸背景图片。 这是一个常见的问题,回答了很多次,所以我在做它的“标准方式”:UITableViewCell backgroundView不拉伸
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
UIImage* bgImg;
bgImg = [[UIImage imageNamed:@"menu_bg_selected.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 1, 0)]; //top/left/bottom/right
cell = [tableView dequeueReusableCellWithIdentifier:@"mycell" forIndexPath:indexPath];
[cell setBackgroundView:[[UIImageView alloc] initWithImage:bgImg]];
return cell;
}
如果我只是试试这个,我得到一个平铺的背景。 阅读几个类似的问题/答案后,我曾尝试:
强制后台查看的规模:背景视图
cell.backgroundView.contentMode = UIViewContentModeScaleToFill;
力大小调整:
cell.backgroundView.clipsToBounds = YES;
面具的设置自动调整大小:
cell.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
;试图为力的背景的帧大小
UIImageView
似乎我的背景图像被部分地拉伸到预定尺寸,然后平铺(没有足够的声誉尚未上传图片,遗憾。 ..):
- 垂直拉伸是局部的和不使用全高
- 横向拉伸是局部的和不使用全宽度
背景图片是一张6x3像素的图片(左侧蓝色垂直线,深灰色背面和底部浅灰色水平线)。
我在做什么错?
感谢您的帮助!
[编辑] 实际上这个问题似乎并不是一个UIEdgeInsetsMake问题。 当使用bgImg = [UIImage imageNamed:@“menu_bg_selected.png”];背景图片仍然没有填充完整的单元格背景。
cell.backgroundView.contentMode = UIViewContentModeTop; –
好吧我知道了,我需要使用resizingMode参数:'bgImg = [[UIImage imageNamed:@“menu_bg_selected.png”] resizableImageWithCapInsets:UIEdgeInsetsMake(0,5,1,0)resizingMode:UIImageResizingModeStretch];' – Noth
I'尽快回答我自己的问题(尽量不要做)。感谢大家的建议! – Noth