0
我正在尝试在我的tableViewCell中为用户的个人资料图片创建一个圆圈imageView。我已经在我的代码中设置了约束条件,Swift Circle图像视图
cell.creatorImageView = UIImageView()
cell.creatorImageView?
.translatesAutoresizingMaskIntoConstraints = false
cell.creatorImageView!.image = UIImage(named: "memoryCardBack")
cell.creatorImageView!.layer.cornerRadius =
(cell.creatorImageView?.bounds.width)!/2
cell.creatorImageView?.clipsToBounds = true
cell.profileCreatorView?.addSubview(cell.creatorImageView!)
NSLayoutConstraint(item: cell.creatorImageView!, attribute: .Width,
relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute,
multiplier: 1, constant: 44).active = true
NSLayoutConstraint(item: cell.creatorImageView!,
attribute: .Height, relatedBy: .Equal, toItem: nil,
attribute: .NotAnAttribute, multiplier: 1, constant: 44)
.active = true
NSLayoutConstraint(item: cell.creatorImageView!, attribute: .Top
, relatedBy: .Equal, toItem: cell.profileCreatorView,
attribute: .Top, multiplier: 1, constant: 5).active = true
NSLayoutConstraint(item: cell.creatorImageView!,
attribute: .CenterX, relatedBy: .Equal,
toItem: cell.profileCreatorView, attribute: .CenterX,
multiplier: 1, constant: 0).active = true
我不太确定为什么imageView没有变成一个圆。
我发现这个问题之后,我张贴这实际上,我在那里设置圆角半径它不是除以宽度的一半。我认为这是因为我在设置宽度约束之前设置了拐角半径。 – tez