【发布时间】:2020-03-04 06:58:00
【问题描述】:
我想要的第一件事是向单元格添加填充,以便带有圆圈和剪刀的图像不会碰到单元格的边框。我已经尝试过cell.layoutMargins = UIEdgeInsets(top: 50, left: 50, bottom: 50, right: 50) 或cell.bounds = CGRect(x: 0, y: 0, width: 100, height: 100)、cell.separatorInset = UIEdgeInsets(top: 100, left: 100, bottom: 100, right: 100) 之类的方法,但没有任何改变。
我想要的第二件事是在单元格之间添加一个间距,我尝试了我找到的所有解决方案,但它似乎不起作用
CODE(我尝试过的一些解决方案都写在下面,但我也一次尝试过)
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "difficultyCell", for: indexPath)
cell.textLabel?.text = myDict[indexPath.row].key
cell.textLabel?.font = .boldSystemFont(ofSize: 20)
let imageCell = UIImage(named: "scissors.png")
cell.imageView?.image = imageCell
cell.backgroundColor = Esercizio.hexStringToUIColor(hex: "#4cf584").withAlphaComponent(0.85)
cell.layer.borderColor = UIColor.orange.cgColor
cell.layer.borderWidth = 1
cell.layer.cornerRadius = 8
cell.layoutMargins = UIEdgeInsets(top: 50, left: 50, bottom: 50, right: 50)
cell.bounds = CGRect(x: 0, y: 0, width: 100, height: 100)
cell.separatorInset = UIEdgeInsets(top: 100, left: 100, bottom: 100, right: 100)
return cell
}
【问题讨论】:
-
你在使用自动布局吗?
-
@SGDev nope only CGRect
-
如果你想要填充和间距使用
UICollectionView -
您可以查看此链接以获取各种解决方案。 stackoverflow.com/questions/6216839/…
标签: ios swift uitableview padding spacing