有什么办法可以在 UITableViewCell
之间添加间距?
我创建了一个表格,每个单元格只包含一个图像。像这样将图像分配给单元格:
cell.imageView.image = [myImages objectAtIndex:indexPath.row];
但这会使图像放大并适合整个单元格,并且图像之间没有间距。
或者可以这样说,图像的高度是例如50,我想在图像之间添加 20 间距。有没有办法做到这一点?
最佳答案
我使用 Swift 的简单解决方案:
// Inside UITableViewCell subclass
override func layoutSubviews() {
super.layoutSubviews()
contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
}
结果
https://stackoverflow.com/questions/6216839/
相关文章:
ios - 何时使用 dequeueReusableCellWithIdentifier 与 deq
iphone - 如何将 NSDictionary 转换为 NSData,反之亦然?
ios - Xcode 调试器不打印对象并显示 nil,当它们不是时
objective-c - cocoa objective-c类中变量前面的下划线如何工作?
ios - UIButton:如何使用 imageEdgeInsets 和 titleEdgeIns
iphone - 真的不应该在生产代码上使用 NSLog() 吗?
objective-c - 在 Objective-C 中创建常量的最佳方法是什么
ios - 是否可以使用 UITableViewStylePlain 禁用 UITableView