问题描述
我通过这种方式设置UICollectionViewCell的边框:
theView.layer.borderWidth = 5
theView.layer.borderColor = UIColor.white.cgColor
问题是我在该collectionviewcell上添加了一个子视图,它像这样在边框下方移动:
我实际上想将子视图带到CollectionViewCell上
plusImageView.translatesAutoresizingMaskIntoConstraints = false
addSubview(plusImageView)
plusImageView.centerYAnchor.constraint(equalTo: bottomAnchor).isActive = true
plusImageView.centerXAnchor.constraint(equalTo: trailingAnchor).isActive = true
解决方法
https://developer.apple.com/documentation/uikit/uiview/1622541-bringsubviewtofront
在将子视图添加到父级后,使用parentView.bringSubviewToFront(subview)。