Subview goes beneath border Layer - Swift - Programmatically

59 views Asked by At

I'm setting border of UICollectionViewCell in this way:

theView.layer.borderWidth = 5
theView.layer.borderColor = UIColor.white.cgColor

The problem is that I'm adding a subview over this collectionviewcell and it goes beneath the border like this:

enter image description here

I actually want to bring the subview over the CollectionViewCell

Code to add subview to cell:

plusImageView.translatesAutoresizingMaskIntoConstraints = false
    addSubview(plusImageView)
    plusImageView.centerYAnchor.constraint(equalTo: bottomAnchor).isActive = true
    plusImageView.centerXAnchor.constraint(equalTo: trailingAnchor).isActive = true
1

There are 1 answers

1
cora On

https://developer.apple.com/documentation/uikit/uiview/1622541-bringsubviewtofront

Use parentView.bringSubviewToFront(subview) after adding subview to parent.