Guest User

Untitled

a guest
Oct 17th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. import UIKit
  2. import SDWebImage
  3.  
  4. private let reuseIdentifier = "safeCircleCell"
  5. private let lastCell = "LastSafeCircleCell"
  6.  
  7. class SafeCircleCollectionViewController: UICollectionViewController {
  8.  
  9. var circleArray: [CircleUser] = [];
  10. var selectedEntry: CircleUser!
  11.  
  12. override func viewDidLoad() {
  13. super.viewDidLoad()
  14.  
  15. // Uncomment the following line to preserve selection between presentations
  16. // self.clearsSelectionOnViewWillAppear = false
  17. }
  18.  
  19. override func viewWillAppear(_ animated: Bool) {
  20. super.viewWillAppear(animated)
  21.  
  22. // TODO Need to add logic to add + button
  23. PackageGuardService.shared.getCircleUsers() {
  24. (circleUsers, error)in
  25. self.circleArray = circleUsers!
  26. self.collectionView?.reloadData()
  27. }
  28. collectionView?.register(LastSafeCircleCell.self, forCellWithReuseIdentifier: lastCell)
  29. }
  30.  
  31. override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  32. // #warning Incomplete implementation, return the number of items
  33. return self.circleArray.count + 1
  34. }
  35.  
  36. override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  37. if indexPath.row == circleArray.count {
  38.  
  39. //try to set the add User button at the last cell
  40.  
  41. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: lastCell, for: indexPath)as? LastSafeCircleCell;
  42. // cell?.btnLabel.text = "add friend"
  43. print("last Cell")
  44. return cell!
  45. } else {
  46. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)as? SafeCircleCell;
  47.  
  48. // set all the user pic and info here and this part work great
  49.  
  50. cell?.safeCircleImage.layer.borderWidth = 2
  51. cell?.safeCircleImage.contentMode = .scaleAspectFill
  52. cell?.safeCircleImage.layer.cornerRadius = (cell?.safeCircleImage.bounds.width)!/2
  53. cell?.safeCircleImage.layer.masksToBounds = true
  54. cell?.safeCircleImage.layer.borderWidth = 0.5
  55.  
  56. let circleEntry = self.circleArray[indexPath.row]
  57. print("safe circle array image (circleEntry.ImageUrl)")
  58.  
  59.  
  60. cell?.setUser(circleUser: circleEntry)
  61.  
  62. return cell!
  63. }
  64. }
  65.  
  66. import UIKit
  67.  
  68. class LastSafeCircleCell: UICollectionViewCell {
  69. let addCircleButton: UIButton = {
  70. let button = UIButton()
  71. button.backgroundColor = UIColor.white
  72. button.layer.cornerRadius = 18
  73. button.clipsToBounds = true
  74. button.setImage(UIImage(named: "add-safe-circle"), for: .normal)
  75.  
  76. return button
  77. }()
  78.  
  79.  
  80. let btnLabel: UILabel = {
  81. let label = UILabel()
  82. label.text = "add Friend"
  83. return label
  84. }()
  85. func addViews(){
  86. backgroundColor = UIColor.black
  87.  
  88. addSubview(addCircleButton)
  89. addSubview(btnLabel)
  90. }
  91. override init(frame: CGRect) {
  92. super.init(frame: frame)
  93. print("lastCell in")
  94. addViews()
  95. }
  96.  
  97. required init?(coder aDecoder: NSCoder) {
  98. fatalError("init(coder:) has not been implemented")
  99. }
  100. }
Add Comment
Please, Sign In to add comment