gpt4 book ai didi

ios - 如何防止 UITableViewCell backgroundView 拉伸(stretch)

转载 作者:行者123 更新时间:2023-11-28 18:24:29 24 4
gpt4 key购买 nike

我正在尝试向 UITableViewCell 添加背景图像,以便每个单元格在底部都有一些间距。

我正在像这样设置单元格的 backgroundView 属性:

 [cell setBackgroundView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cell"]]];

“单元格”图像比 UITableViewCell 的实际高度高 20 像素,这是故意的,这样我的单元格可以在底部有一些间距。唯一的问题是,“单元格”图像会一直拉伸(stretch)到单元格的 contentView。

有什么方法可以防止单元格一直向下拉伸(stretch) backgroundView 吗?

提前致谢!

最佳答案

查看 contentMode UIView 的属性。如果背景图像的高度小于单元格的高度,并且您希望图像“贴在顶部”,请尝试设置

cell.backgroundView.contentMode = UIViewContentModeTop;

查看 this page 上的“内容模式”部分了解更多信息。它提到...

"By default, the contentMode property for most views is set to UIViewContentModeScaleToFill, which causes the view’s contents to be scaled to fit the new frame size."

关于ios - 如何防止 UITableViewCell backgroundView 拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13080232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com