Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import SDWebImage
- private let reuseIdentifier = "safeCircleCell"
- private let lastCell = "LastSafeCircleCell"
- class SafeCircleCollectionViewController: UICollectionViewController {
- var circleArray: [CircleUser] = [];
- var selectedEntry: CircleUser!
- override func viewDidLoad() {
- super.viewDidLoad()
- // Uncomment the following line to preserve selection between presentations
- // self.clearsSelectionOnViewWillAppear = false
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- // TODO Need to add logic to add + button
- PackageGuardService.shared.getCircleUsers() {
- (circleUsers, error)in
- self.circleArray = circleUsers!
- self.collectionView?.reloadData()
- }
- collectionView?.register(LastSafeCircleCell.self, forCellWithReuseIdentifier: lastCell)
- }
- override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- // #warning Incomplete implementation, return the number of items
- return self.circleArray.count + 1
- }
- override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- if indexPath.row == circleArray.count {
- //try to set the add User button at the last cell
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: lastCell, for: indexPath)as? LastSafeCircleCell;
- // cell?.btnLabel.text = "add friend"
- print("last Cell")
- return cell!
- } else {
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)as? SafeCircleCell;
- // set all the user pic and info here and this part work great
- cell?.safeCircleImage.layer.borderWidth = 2
- cell?.safeCircleImage.contentMode = .scaleAspectFill
- cell?.safeCircleImage.layer.cornerRadius = (cell?.safeCircleImage.bounds.width)!/2
- cell?.safeCircleImage.layer.masksToBounds = true
- cell?.safeCircleImage.layer.borderWidth = 0.5
- let circleEntry = self.circleArray[indexPath.row]
- print("safe circle array image (circleEntry.ImageUrl)")
- cell?.setUser(circleUser: circleEntry)
- return cell!
- }
- }
- import UIKit
- class LastSafeCircleCell: UICollectionViewCell {
- let addCircleButton: UIButton = {
- let button = UIButton()
- button.backgroundColor = UIColor.white
- button.layer.cornerRadius = 18
- button.clipsToBounds = true
- button.setImage(UIImage(named: "add-safe-circle"), for: .normal)
- return button
- }()
- let btnLabel: UILabel = {
- let label = UILabel()
- label.text = "add Friend"
- return label
- }()
- func addViews(){
- backgroundColor = UIColor.black
- addSubview(addCircleButton)
- addSubview(btnLabel)
- }
- override init(frame: CGRect) {
- super.init(frame: frame)
- print("lastCell in")
- addViews()
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
Add Comment
Please, Sign In to add comment