Files
Woka_Native_iOS/WOKA/Authentication/Controller/UserIntrestVC.swift

118 lines
4.5 KiB
Swift
Raw Normal View History

2024-05-02 13:20:40 +05:30
//
// UserIntrestVC.swift
// WOKA
//
// Created by MacBook Pro on 30/04/24.
//
import UIKit
2024-05-02 19:30:09 +05:30
struct Temp{
let text : String?
var selected : Bool?
}
2024-05-02 13:20:40 +05:30
class UserIntrestVC: UIViewController {
2024-05-02 19:30:09 +05:30
2024-05-02 13:20:40 +05:30
@IBOutlet weak var boyView: UIView!
@IBOutlet weak var girlView: UIView!
@IBOutlet weak var datePicker: UIDatePicker!
2024-05-02 19:30:09 +05:30
@IBOutlet weak var collectionView: UICollectionView!
@IBOutlet weak var nextBtn: LocalisedElementsButton!
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var contentHeight: NSLayoutConstraint!
2024-05-02 13:20:40 +05:30
var vm = UserIntrestVM()
2024-05-02 19:30:09 +05:30
var test = [Temp(text: "ADVENTURES", selected: false),
Temp(text: "CARTOONS", selected: false),
Temp(text: "SUPER HEROES", selected: false),
Temp(text: "SPORTS", selected: false),
Temp(text: "SCIENCE", selected: false),
Temp(text: "TRAVEL", selected: false),
Temp(text: "ADVENTURES", selected: false),
Temp(text: "CARTOONS", selected: false),
Temp(text: "SUPER HEROES", selected: false),
Temp(text: "SPORTS", selected: false),
Temp(text: "SCIENCE", selected: false),
Temp(text: "TRAVEL", selected: false)]
2024-05-02 13:20:40 +05:30
override func viewDidLoad() {
super.viewDidLoad()
vm.vc = self
vm.initView()
boyView.roundCorner(radius: 25)
girlView.roundCorner(radius: 25)
datePicker.setValue(UIColor.appColor(.TextDarkBlue), forKeyPath: "textColor")
2024-05-02 19:30:09 +05:30
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(false, animated: animated)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
navigationController?.setNavigationBarHidden(true, animated: animated)
}
@IBAction func nextBtnTapped(_ sender: LocalisedElementsButton) {
let sb = UIStoryboard(name: K.StoryBoard.authenticationSB, bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: K.StoryBoardID.Authentication.selectAvatarVC) as! SelectAvatarVC
self.navigationController?.pushViewController(vc, animated: true)
}
}
2024-05-02 13:20:40 +05:30
2024-05-02 19:30:09 +05:30
// MARK: - CollectionView Delegate
extension UserIntrestVC : UICollectionViewDelegate , UICollectionViewDataSource{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return vm.intrestTopics.count
2024-05-02 19:30:09 +05:30
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: K.CellIdentifier.Authentication.yourIntrestCell, for: indexPath) as! YourIntrestCell
cell.setData(data: vm.intrestTopics[indexPath.row])
2024-05-02 19:30:09 +05:30
return cell
2024-05-02 13:20:40 +05:30
}
2024-05-02 19:30:09 +05:30
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
vm.intrestTopics[indexPath.row].isSelected?.toggle()
2024-05-02 19:30:09 +05:30
UIView.performWithoutAnimation {
self.collectionView.reloadItems(at: [IndexPath(row: indexPath.row, section: 0)])
}
}
}
// MARK: - Collection Flow Layout
extension UserIntrestVC : UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
// Generate a random string for testing purposes
let randomText = test[indexPath.row].text!
// Define the font for the text
let font = UIFont.systemFont(ofSize: 14) // You can adjust the font size as needed
// Calculate the width of the text
let textWidth = randomText.size(withAttributes: [.font: font]).width
// Set the cell width based on the text width and any additional padding
let cellWidth = textWidth + 25 // Add any additional spacing you want
return CGSize(width: cellWidth, height: 45)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
section == 0 ? 15 : 5
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
}
2024-05-02 13:20:40 +05:30
}