pod 'VTAutoSlideView'
to your Podfile.pod install
or pod update
in the terminal..package(url: "https://github.com/VitoNYang/VTAutoSlideView.git")
in Storyboard or Xib create a View, and set the View's class as VTAutoSlideView
,
create a UICollectionViewCell and build as the UI as you want,
register your cell in the caller, and setup VTAutoSlideView dataSource
and dataList
.
@IBOutlet weak var slideView: VTAutoSlideView!
// Your data sources
lazy var imageList = {
(1...4).map{ "0\($0)" }.map{ UIImage(named: $0) }.filter{ $0 != nil }.map{ $0! }
}()
override func viewDidLoad() {
super.viewDidLoad()
// register your CollectionViewCell first
// Case 1: use Xib
slideView.register(nib: UINib(nibName: "DisplayImageCell", bundle: nibBundle))
// Case 2: Or use pure code
//slideView.register(cellClass: DisplayImageCell.self)
slideView.dataSource = self
slideView.dataList = imageList
}
implement VTAutoSlideViewDataSource's configuration(cell:for) method and configure your cell
extension ViewController: VTAutoSlideViewDataSource {
func configuration(cell: UICollectionViewCell, for index: Int)
{
guard let cell = cell as? DisplayImageCell else {
return
}
cell.imageView.image = imageList[index]
}
}
finally, all should be set up! Run your project and if anything is configured, it should work fine🍻🍻
Create VTAutoSlideView with direction and setup dataSource
let slideView = VTAutoSlideView(direction: .vertical, dataSource: self)
register cell,and set dataList
slideView.register(nib: UINib(nibName: "DisplayImageCell", bundle: nibBundle))
slideView.dataList = imageList
slideView.activated = false // disable auto slide
view.addSubview(slideView)
slideView.translatesAutoresizingMaskIntoConstraints = false
// add constraints
slideView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
slideView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor, constant: 20).isActive = true
slideView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
slideView.heightAnchor.constraint(equalToConstant: view.bounds.height * 0.5).isActive = true
实现 VTAutoSlideViewDataSource 的 configuration(cell:for) 方法,配置你的 cell (参考 Storyboard / Xib 中的代码)
没有配置错的话,一切也已经可以正常运行起来了。
Please contact me via Email : [email protected]
VTAutoSlideView is released under the MIT license. See LICENSE for details.
link |
Stars: 0 |
Last commit: 1 week ago |
First release for this library
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics