-
Notifications
You must be signed in to change notification settings - Fork 54
/
CollectionViewCell.swift
37 lines (30 loc) · 1019 Bytes
/
CollectionViewCell.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// CollectionViewCell.swift
// PinterestLayout
//
// Created by Khrystyna Shevchuk on 7/4/17.
// Copyright © 2017 MagicLab. All rights reserved.
//
import UIKit
import PinterestLayout
class CollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var imageViewHeightLayoutConstraint: NSLayoutConstraint!
@IBOutlet weak var descriptionLabel: UILabel!
var image: UIImage? {
didSet {
if let image = image {
imageView.image = image
} else {
imageView.backgroundColor = .lightGray
}
}
}
override func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
super.apply(layoutAttributes)
if let attributes = layoutAttributes as? PinterestLayoutAttributes {
//change image view height by changing its constraint
imageViewHeightLayoutConstraint.constant = attributes.imageHeight
}
}
}