FSPagerView icon indicating copy to clipboard operation
FSPagerView copied to clipboard

FSPagerView create custom cell

Open nadia-am opened this issue 5 years ago • 10 comments

My cell in FSPagerView is not just an image view and text , actually my cell should have an image view , 3 label and 2 button in it. i create it base on structure in Readme and issues but it return error : Unknown class _TtC19viewPagerCustomCell19viewPagerCustomCell in Interface Builder file. class viewPagerCustomCell : FSPagerViewCell { ...... }

@IBOutlet weak var PagerView: FSPagerView!{ didSet { self.PagerView.register(UINib(nibName: "viewPagerCustomCell", bundle: nil), forCellWithReuseIdentifier: "cell")// error occur } }

public func numberOfItems(in pagerView: FSPagerView) -> Int { self.PageControl.numberOfPages = 5 return 5 }

func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell { let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index) as! viewPagerCustomCell return cell }

and in design I create a UIView and subclass it FSPagerView

nadia-am avatar Apr 15 '19 08:04 nadia-am

@nadia-am have you resolve this. Please share the solution.

Satishphogat1 avatar Apr 19 '19 10:04 Satishphogat1

@Satishphogat1 no i didnt :(

nadia-am avatar Apr 20 '19 06:04 nadia-am

I don't know you already solved this problem but I reached here somehow and here is what I did.

  1. Create xib file.

  2. From xib, Make one view and subclass it FSPagerViewCell.

  3. Comeback to your storyboard, Add empty UIView and subclass it FSPagerView.

  4. Connect FSPagerView to source file and add like under. @IBOutlet weak var pagerV: FSPagerView! { didSet { self.pagerV.register(UINib(nibName:"<NIB FILE NAME>", bundle: Bundle.main), forCellWithReuseIdentifier: "cell") } }

  5. Then you can see your cell from FSPagerView.

CheeseStick avatar May 19 '19 05:05 CheeseStick

@CheeseStick can you share a demo code. Can't seem to figure it out.

gurpreetsinghgulati13 avatar Jun 30 '20 10:06 gurpreetsinghgulati13

@gurpreetsinghgulati13 Just uploaded a sample demo test project for what I did. It's bit long times ago so I simply copied and paste codes from old project.

https://github.com/CheeseStick/FSPagerViewCellTest

CheeseStick avatar Aug 03 '20 23:08 CheeseStick

Side note for all Obj-C users: unfortunately subclassing a Swift class in Obj-C is not supported, therefore a custom FSPagerViewCell in an Obj-C project is not possible.

Xcode error message:

Cannot subclass a class that was declared with the 'objc_subclassing_restricted' attribute

skuske avatar Aug 05 '20 07:08 skuske

I'm new to iOS development. Can you share your code?

JegaJegatheesh avatar Jan 09 '21 06:01 JegaJegatheesh

@gurpreetsinghgulati13 Just uploaded a sample demo test project for what I did. It's bit long times ago so I simply copied and paste codes from old project.

https://github.com/CheeseStick/FSPagerViewCellTest

Please share the correct code link

shouaib07 avatar Apr 29 '21 06:04 shouaib07

https://github.com/CheeseStick/FSPagerViewCellTest

https://github.com/CheeseStick/FSPagerViewCellTest Or just open the profile of @CheeseStick and search in repositories

swarajsinghdev avatar Jul 08 '22 07:07 swarajsinghdev

FSPager has a function to register nib, so you can create custom nib cell and register it Screenshot 2023-01-17 at 2 26 01 PM

O-labib avatar Jan 17 '23 12:01 O-labib