Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- @IBOutlet weak var collectionView: UICollectionView!
- @IBOutlet weak var continueButton: RoundedButton!
- @IBOutlet weak var notSureButton: RoundedButton!
- @IBOutlet weak var notSureButtonTop: NSLayoutConstraint!
- var collectionData = [[String: String]]()
- override func viewDidLoad() {
- super.viewDidLoad()
- self.appointment = fetchAppointment()
- self.collectionView.delegate = self
- self.collectionView.dataSource = self
- self.collectionData.append([
- "image": "regularExam",
- "text": "Regular Exam",
- "data": "regular_exam"])
- self.collectionData.append([
- "image": "vaccines",
- "text": "Essential Vaccines",
- "data": "vaccines"])
- self.collectionData.append([
- "image": "meds",
- "text": "Parasite Meds",
- "data": "preventitive_meds"])
- self.collectionData.append([
- "image": "dog",
- "text": "My pet is sick",
- "data": "sick_pet"])
- self.notSureButton.layer.shadowColor = Constants.appColor.gray.light.cgColor
- self.notSureButton.layer.shadowOffset = CGSize(width: 0, height: 2.0)
- self.notSureButton.layer.shadowRadius = 3.0
- self.notSureButton.layer.shadowOpacity = 0.8
- self.notSureButton.layer.masksToBounds = false
- }
- override func viewDidLayoutSubviews(){
- self.collectionView.frame = CGRect(x: self.collectionView.frame.origin.x, y: self.collectionView.frame.origin.y, width: self.collectionView.frame.size.width, height: CGFloat(2 * 170))
- self.notSureButtonTop.constant = CGFloat(2 * 170) + 20.0
- self.view.layoutIfNeeded()
- self.collectionView.reloadData()
- }
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
- return self.collectionData.count
- }
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "SelectVisitForCollectionViewCell", for: indexPath) as! SelectVisitForCollectionViewCell
- let item = indexPath.item
- cell.displayContent(image: UIImage(named: self.collectionData[item]["image"]!)!, text: self.collectionData[item]["text"]!)
- return cell
- }
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
- if let cell = collectionView.cellForItem(at: indexPath) as? SelectVisitForCollectionViewCell {
- var categories = self.appointment?.categories
- if let index = categories!.index(of: self.collectionData[indexPath.item]["data"]!) {
- categories?.remove(at: index)
- cell.showSelected(false)
- } else {
- categories?.append(self.collectionData[indexPath.item]["data"]!)
- cell.showSelected(true)
- }
- self.appointment?.categories = categories!
- if (self.appointment?.categories.count)! > 0 {
- self.continueButton.isHidden = false
- } else {
- self.continueButton.isHidden = true
- }
- saveAppointment(data: self.appointment!)
- }
- }
- @IBAction func onNotSureButtonPressed(_ sender: Any) {
- var categories = self.appointment?.categories
- if let index = categories!.index(of: "not_sure") {
- categories?.remove(at: index)
- self.notSureButton.backgroundColor = UIColor.white
- self.notSureButton.setTitleColor(Constants.appColor.gray.dark, for: .normal)
- } else {
- categories?.append("not_sure")
- self.notSureButton.backgroundColor = Constants.appColor.yellow.main
- self.notSureButton.setTitleColor(UIColor.white, for: .normal)
- }
- self.appointment?.categories = categories!
- if (self.appointment?.categories.count)! > 0 {
- self.continueButton.isHidden = false
- } else {
- self.continueButton.isHidden = true
- }
- print(self.appointment?.categories)
- saveAppointment(data: self.appointment!)
- }
- @IBAction func onContinueButtonPressed(_ sender: Any) {
- self.parentPageboy?.scrollToPage(.next, animated: true)
- }
Add Comment
Please, Sign In to add comment