- In this blog we will know about the mpskewed in swift
- Please create a new project or you can use this in the existing product in which you want to implement Mpskewed
2. Then you need to add pod in the project
1 |
pod "MPSkewed" |
3. then you need to import the library in the controller
1 |
<strong>import</strong> MPSkewed |
4 you have to add collection view in the controller
After this done you call the class from the imported library and add its scal in view didload
1 2 3 |
let layout = MPSkewedParallaxLayout() layout.lineSpacing = 2 layout.itemSize = CGSize(width: view.bounds.width, height: 250) |
set the delegate and datasource and register the cell in the controller
1 2 3 4 |
self.collectionview.delegate = self; self.collectionview.dataSource = self; self.collectionview.register(UINib(nibName: "cell", bundle: nil), forCellWithReuseIdentifier: "cell") |
5. Add layout subview in the controller
1 2 3 |
override func viewDidLayoutSubviews() { (collectionview.collectionViewLayout as? MPSkewedParallaxLayout)?.itemSize = CGSize(width: view.bounds.width, height: 250) } |
6. Add title for the mpskewed cell
this will set the title or name which you want to set in the cell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
func title(for index: Int) -> String? { var text: String? = nil switch index - 1 { case 0: text = "s1\n hot" case 1: text = "s2\n cold" case 2: text = "s3\n warm" case 3: text = "s4\n red" case 4: text = "s5\n beach" default: break } return text } |
7. call the collection view delegate and datasource method
you have to the use cell as MPSkewedCell
you can set images in the collection view cell
for the title in the cell it will call random at the time of execution
1 2 3 4 5 6 7 8 9 10 11 |
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 10 } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let index = indexPath.item % 5 + 1 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as? MPSkewedCell cell?.image = UIImage(named: String(format: "%zd", index)) cell?.text = title(for: index) as NSString? return UICollectionViewCell() } |
Then you can get the output as bolow
Thanks for reading 🙂
Hope this blog helped you with a better understanding of MpSkewed.
For more technical blogs please visit here.
For more detail about the mpskewed please click here
If you have any query/doubt please u comment