Tap to scroll functionality in a single view with multiple images
Obi-codes opened this issue · comments
Report
Fairy new to Xcode and SwiftUI, working with UIkit. Im just stuck on how to add multiple images in a single demo card view. I'm aware you could create a custom view and load it inside koloda(_:viewForCardAt:) but I don't understand how. Please show me the light and help me make the connection!
### What I wrote?
import Koloda
class CustomView: UIView {
let imageView: UIImageView = {
let imageView = UIImageView()
imageView.translatesAutoresizingMaskIntoConstraints = false
return imageView
}()
override init (frame: CGRect) {
super.init (frame: frame)
self.addSubview(imageView)
imageView.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
imageView.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true
imageView.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
imageView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
}
required init?(coder aDecoder: NSCoder) {
fatalError()
}
}
extension HomeViewController: KolodaViewDataSource {
func koloda(_ koloda: KolodaView, viewForCardAt index: Int) -> UIView {
let view = Bundle.main.loadNibNamed("CardView", owner: self, options: nil)?[0] as! CardView
view.delegate = self
view.imgView.image = UIImage(named: "\(index+1)")
view.imgLogo.image = UIImage(named: "sample_logo_\(index+1)")
return view
}
}
### **Resources Used**
https://www.youtube.com/watch?v=IUT0WByY7HI&t=838s
https://www.youtube.com/watch?v=X2Wr4TtMG6Q
### Your Environment
- Version of the component: N/A
- Swift version: 5.3
- iOS version: 14.2
- Device: IOS simulator
- Xcode version: 12.3
I have found the solution using view model view state reactive programming, representing what I want in the Card View and implementing that in the extension function (:viewforCardat index). If you need more details let me know