【发布时间】:2020-07-29 05:43:33
【问题描述】:
我在 UITableViewCell 中放置了一张背景图片,以使其更具视觉吸引力。在 iOS 13 中,背景图像被重新排序控件剪裁。
旧版本的操作系统不会发生这种情况。
代码很简单:
// Put a border around mBackgroundImage. Make it slightly smaller than the size of the cell so that the border doesn't run all the way to the edges.
cell.mBackgroundImage.frame = CGRectMake(2, 2, cell.frame.size.width-4, cell.frame.size.height-4);
cell.mBackgroundImage.layer.cornerRadius = 4;
cell.mBackgroundImage.layer.borderColor = [UIColor colorWithWhite:0.92 alpha:1.0].CGColor;
cell.mBackgroundImage.layer.borderWidth = 1;
cell.mBackgroundImage.layer.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.95 alpha:1.0].CGColor;
有什么建议吗?
【问题讨论】:
-
您是将
mBackgroundImage添加到cell还是cell的contentView? -
mBackgroundImage 在单元格的 contentView 中。
-
啊哈!我根据单元格的框架调整 mBackgroundImage 的大小,而不是 contentView 的框架。并且似乎 cell.contentView.clipsToBounds 的默认设置在 iOS 13 中已更改。如果我明确将其设置为 NO,我会得到所需的行为。感谢您为我指明正确的方向!
-
再想一想,我认为可能发生的事情是 iOS 13 修复了以前版本的 iOS 中的一个错误:cell.contentView.clipsToBounds=YES 已被忽略。
-
您应该在
layoutSubviews中操作图层。你的代码在哪里?
标签: ios objective-c swift iphone uitableview