Tusker/Tusker/Views/Asset Picker/AllPhotosTableViewCell.swift

38 lines
1.1 KiB
Swift

//
// AllPhotosTableViewCell.swift
// Tusker
//
// Created by Shadowfacts on 1/4/20.
// Copyright © 2020 Shadowfacts. All rights reserved.
//
import UIKit
import Photos
class AllPhotosTableViewCell: UITableViewCell {
@IBOutlet weak var thumbnailImageView: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
thumbnailImageView.layer.masksToBounds = true
thumbnailImageView.layer.cornerRadius = 0.05 * thumbnailImageView.bounds.width
let options = PHFetchOptions()
options.fetchLimit = 1
options.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
let fetchResult = PHAsset.fetchAssets(with: options)
if fetchResult.count == 1 {
let asset = fetchResult.object(at: 0)
let size = thumbnailImageView.bounds.size
PHImageManager.default().requestImage(for: asset, targetSize: size, contentMode: .aspectFill, options: nil) { (image, _) in
self.thumbnailImageView.image = image
}
} else {
thumbnailImageView.image = nil
}
}
}