gpt4 book ai didi

ios - 表格 View 中的自定义单元格不希望被舍入

转载 作者:行者123 更新时间:2023-12-01 16:19:48 24 4
gpt4 key购买 nike

大家!
我的问题听起来像这样:
我想在iPhone的应用程序中将自定义单元格四舍五入。但是当我尝试做这样的事情时:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as? MainTableViewCell
else { fatalError("DequeueReusableCell failed while casting") }
cell.imageView?.layer.cornerRadius = cell.frame.size.height / 2
cell.imageView?.clipsToBounds = true
cell.imageView?.contentMode = .scaleAspectFill
cell.textLabel?.textColor = #colorLiteral(red: 0.03921568627, green: 0.3969546359, blue: 1, alpha: 1)
cell.textLabel?.font = UIFont(name: "EuphemiaUCAS", size: 22)
cell.textLabel?.text = restaurantNames[indexPath.row]
cell.textLabel?.numberOfLines = 0
cell.imageView?.image = UIImage(named: restaurantNames[indexPath.row])
return cell
}
// MARK: - Table View Delegate
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 85
}
我有一个奇怪的结果: Result #1
但是,当我更改此行时:
cell.imageView?.layer.cornerRadius = cell.frame.size.height / 2
对此:
cell.imageView?.layer.cornerRadius = 85 / 2
如您所见,一切都井井有条:
Result #2
但这不是解决问题的正确方法
感谢所有答案!

最佳答案

将其添加到您的单元格类而不是cellForRow中

class MainTableViewCell: UITableViewCell {

override func layoutSubviews() {
imageOfPlace.layer.cornerRadius = imageOfPlace.bounds.midY // or imageOfPlace.bounds.height/2
imageOfPlace.clipsToBounds = true
}
}

关于ios - 表格 View 中的自定义单元格不希望被舍入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63327664/

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