FSPagerView icon indicating copy to clipboard operation
FSPagerView copied to clipboard

Register custom cell

Open dkcas11 opened this issue 7 years ago • 14 comments

Hey,

I would like to use your library to implement centered cells with custom width, and infinite scrolling. But trying to register my custom cell - that subclasses FSPagerViewCell - still produces a normal FSPagerViewCell. I cast the cell to my custom cell in cellForItemAt.

Also, for some reason i cannot scroll the PagerView?

Thanks :)

dkcas11 avatar Feb 20 '17 13:02 dkcas11

Hi @dkcas11 Can you provide a demo project link which reproduces and demonstrates your issue?

Thanks.

WenchaoD avatar Feb 21 '17 00:02 WenchaoD

Hey @WenchaoD

I basically just copy/pasted your code in, from the README and use the frame from my existing UICollectionView (which i then set isHidden = true) and the same frame for pageControl too.

The cell is here https://www.dropbox.com/s/9hp7kw9s5hl0lrw/Custom%20Cell.zip?dl=1 (Without subclassing FSPagerViewCell, i reverted it to continue working :))

dkcas11 avatar Feb 21 '17 09:02 dkcas11

I have the same problem. I hope it will be handled quickly.

self.pagerView.registerNib(UINib(nibName: "CustomPagerViewCell", bundle: nil), forCellWithReuseIdentifier: "cell")

Value of type 'FSPagerView' has no member 'registerNib'"

I wish that I wanted to implement it through NIB. But I received the message above.

thenopen avatar Feb 22 '17 07:02 thenopen

Hey guys. The function registerNib has been added. Please notice that the object in your nib file must be UICollectionViewCell object rather than UIView. Then you need to change the custom class to the class name of the FSPagerViewCell subclass.

WenchaoD avatar Feb 22 '17 09:02 WenchaoD

@dkcas11 If you cannot find 0.2.0 in CocoaPods, probably you should try pod repo update.

| screen shot 2017-02-22 at 8 06 37 pm

WenchaoD avatar Feb 22 '17 12:02 WenchaoD

Yea, i forgot i had removed it again... D'oh.. :)

dkcas11 avatar Feb 22 '17 12:02 dkcas11

Okay, so right now it works, but it looks like the normal square cells are still behind my custom cell? My custom cell have rounded corners and a subtle shadow. I can make the background disappear so i have the rounded corners again with masksToBounds, but then i lose the shadow. Is this a bug? Here are two screenshots. Looks wrong: http://imgur.com/vW70PWT Looks "right": http://imgur.com/BGkVhDu

Apart from this it really works smooth and well!

dkcas11 avatar Feb 22 '17 12:02 dkcas11

Hi @dkcas11

  1. I don't quite understand what does this mean: normal square cells are still behind my custom cell
  2. To keep the shadow, maybe you should try mask the imageView or the contentView of the cell instead.

WenchaoD avatar Feb 24 '17 01:02 WenchaoD

@WenchaoD What i meant was actually the contentView. I had yet to inspect the class, so i was unaware of that view. I set the background to clear and remove the shadow, so it all looks almost perfect :) I still have the clipping at the top and at the bottom though. I tried to set PagerView's clipsToBounds to false, but that didn't do the trick, for some reason. You can see what i mean here: http://i.imgur.com/OE1neKj.gif

dkcas11 avatar Feb 24 '17 09:02 dkcas11

@dkcas11 I've been confused about this problem too. This workaround works for me.

// Clear background colors in FSPagerViewCell subclass
self.contentView.backgroundColor = UIColor.clear
self.backgroundColor = UIColor.clear

WenchaoD avatar Feb 28 '17 06:02 WenchaoD

@WenchaoD I have already done that to the cell. The issue lies with the PagerView, since its that which clips the content. I tried to turn off clipsToBounds and also masksToBounds for both the PagerView and it's contenView, so far without luck.

pagerView.clipsToBounds = false
pagerView.layer.masksToBounds = false
pagerView.backgroundView?.clipsToBounds = false
pagerView.backgroundView?.layer.masksToBounds = false

I have really run out of ideas of where the issue is..

dkcas11 avatar Feb 28 '17 08:02 dkcas11

Like This: @IBOutlet weak var pagerView: FSPagerView! { didSet { let nib = UINib(nibName: "CustomCell", bundle: nil) self.pagerView.register(nib,forCellWithReuseIdentifier: "myID") } }

override func viewDidLoad() {
    super.viewDidLoad()
    pagerView.transformer = FSPagerViewTransformer(type: .linear)       
    
}

var names = ["File1","File26","File3","File7","File8","File9","File10"]

public func numberOfItems(in pagerView: FSPagerView) -> Int {
    return 5
}

public func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell {
    let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "myID", at: index) as! CustomCell
    cell.btn.setImage(UIImage(named: names[index]), for: .normal)
    cell.btn.setTitle(names[index], for: .normal)
    cell.lbl.text = names[index]
    return cell
}`

Saleh-At avatar Nov 20 '17 17:11 Saleh-At

I have custom page cell, i added FSPageControll in my custom cell. But when i'm going to access to member of FSPageControll, the member is nil. I've created my custom XIB and put FSPageControll into that. But FSPageControl always nil. Why? Any Suggest?

alcalyx avatar May 12 '19 12:05 alcalyx

I have custom page cell, i added FSPageControll in my custom cell. But when i'm going to access to member of FSPageControll, the member is nil. I've created my custom XIB and put FSPageControll into that. But FSPageControl always nil. Why? Any Suggest?

I had the same problem, this worked for me:

@IBOutlet weak var pagerView: FSPagerView! { didSet { let nib = UINib(nibName: "CustomPagerViewCell", bundle: nil) self.pagerView.register(nib, forCellWithReuseIdentifier: "CustomPagerViewCell") } }

and do not forget to set reuseIdentifier inside xib.

sebanoidze avatar Jan 23 '20 07:01 sebanoidze