I need to use my UIView custom class in UICollectionViewHeader
Here is my UIView class code
class ViewPlayerHeader: UIView {
@IBOutlet weak var contentView: UIView!
@IBOutlet weak var imgViewCoverPhoto: UIImageView!
@IBOutlet weak var imgViewUserPic: UIImageView!
@IBOutlet weak var lblPlayerName: VVLabel!
@IBOutlet weak var lblCountryname: VVLabel!
@IBOutlet weak var lblPlayedFor: VVLabel!
var arrSportsIcon:NSMutableArray!
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override init(frame: CGRect) { // for using CustomView in code
super.init(frame: frame)
commonInit()
}
required init?(coder aDecoder: NSCoder) { // for using CustomView in IB
super.init(coder: aDecoder)
commonInit()
}
override func draw(_ rect: CGRect) {
// Drawing code
}
private func commonInit () {
Bundle.main.loadNibNamed("ViewPlayerHeader", owner: self, options: nil)
addSubview(contentView)
contentView.frame = self.bounds
contentView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
imgViewUserPic.layer.borderColor = UIColor.white.cgColor
imgViewUserPic.layer.borderWidth = 2.0
}
}
Updated -> add colleciton view header code
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
switch kind {
case UICollectionView.elementKindSectionHeader:
let headerView = ViewPlayerHeader.init(frame: CGRect(x: 0, y: 0, width: self.collectionViewInfo.frame.size.width, height: 50))
return headerView
default:
assert(false, "Unexpected element kind")
}
}