【发布时间】:2018-10-26 21:39:09
【问题描述】:
我正在尝试在 TableViewCell 内创建圆形图像,但出现了问题。我猜cornerRadius 太大了,因为此代码没有显示任何图像。例如,如果我将cornerRadius 设置为 30,我可以看到图像是圆形的,但不是一个清晰的圆圈。为什么这不起作用?
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "QuestionLine")
cell = UITableViewCell(style: .subtitle, reuseIdentifier: "QuestionLine")
let user = users[indexPath.row]
cell?.textLabel?.text = user.question
cell?.detailTextLabel?.text = user.name
let image = UIImage(named: user.profilePicture)
cell?.imageView?.image = image
cell?.imageView?.layer.cornerRadius = (image?.size.width)! / 2
cell?.imageView?.clipsToBounds = true
return cell!
}
【问题讨论】:
-
你应该使用 imageView 帧大小而不是图像大小
-
好的,但这没有帮助:/
-
编辑您的问题并添加您的实际代码
标签: ios swift uitableview uiimageview