mirror of
https://github.com/Instagram/IGListKit
synced 2026-05-06 15:08:50 +00:00
Summary: ## Changes in this pull request ### Checklist - [x] All tests pass. Demo project builds and runs. - [x] I added tests, an experiment, or detailed why my change isn't tested. - [x] I added an entry to the `CHANGELOG.md` for any breaking changes, enhancements, or bug fixes. - [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md) Pull Request resolved: https://github.com/Instagram/IGListKit/pull/1453 Reviewed By: lorixx Differential Revision: D23836038 Pulled By: joetam fbshipit-source-id: 8245415992a5b1ed49f67ebfcf9f85a2745a8042
53 lines
1.4 KiB
Swift
53 lines
1.4 KiB
Swift
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import UIKit
|
|
|
|
final class ImageCell: UICollectionViewCell {
|
|
|
|
fileprivate let imageView: UIImageView = {
|
|
let view = UIImageView()
|
|
view.contentMode = .scaleAspectFill
|
|
view.clipsToBounds = true
|
|
view.backgroundColor = UIColor.secondaryBackground
|
|
return view
|
|
}()
|
|
|
|
fileprivate let activityView: UIActivityIndicatorView = {
|
|
let view = UIActivityIndicatorView()
|
|
view.style = UIActivityIndicatorView.defaultStyle
|
|
view.startAnimating()
|
|
return view
|
|
}()
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
contentView.addSubview(imageView)
|
|
contentView.addSubview(activityView)
|
|
}
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func layoutSubviews() {
|
|
super.layoutSubviews()
|
|
let bounds = contentView.bounds
|
|
activityView.center = CGPoint(x: bounds.width / 2.0, y: bounds.height / 2.0)
|
|
imageView.frame = bounds
|
|
}
|
|
|
|
func setImage(image: UIImage?) {
|
|
imageView.image = image
|
|
if image != nil {
|
|
activityView.stopAnimating()
|
|
} else {
|
|
activityView.startAnimating()
|
|
}
|
|
}
|
|
|
|
}
|