[英]Add mask border after masking UIImageView with mask property
I managed to get a mask for a UIImageView from a png using the .mask
property but was wondering if there was any simple way to draw a border around the mask. 我设法使用.mask
属性从png获取了UIImageView的蒙版,但想知道是否有任何简单的方法可以在蒙版周围绘制边框。
What it looks like: 看起来像什么:
Code (UICollectionViewCell) : 代码(UICollectionViewCell) :
lazy var maskingView: UIImageView = {
let view = UIImageView()
view.image = UIImage(named: "mask")
return view
}()
lazy var profilePictureContainerView: UIImageView = {
let containerView = UIImageView()
containerView.backgroundColor = .black
containerView.translatesAutoresizingMaskIntoConstraints = false
return containerView
}()
override func layoutSubviews() {
super.layoutSubviews()
maskingView.frame = profilePictureContainerView.bounds
}
override init(frame: CGRect) {
super.init(frame: frame)
profilePictureContainerView.mask = maskingView
setUpViews()
}
setUpViews()
is a func simply laying out a Collection View Cell and positioning the profilePictureContainerView
inside it. setUpViews()
是一个函数,只需布置一个Collection View单元并在其中放置profilePictureContainerView
。
What I want to achieve 我想要达到的目标
Put a border, say red, around the black shape (ie, the mask's "interior edge"). 在黑色形状(即面罩的“内边缘”)周围放置一个边框,例如红色。
Any ideas ? 有任何想法吗 ?
Did you try with layer? 您尝试过图层吗?
maskingView.layer.borderWidth = 1 // Or any width
maskingView.layer.borderColor = UIColor.red.cgColor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.