Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register custom cell #8

Open
dkcas11 opened this issue Feb 20, 2017 · 14 comments
Open

Register custom cell #8

dkcas11 opened this issue Feb 20, 2017 · 14 comments

Comments

@dkcas11
Copy link

dkcas11 commented Feb 20, 2017

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 :)

@WenchaoD
Copy link
Owner

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

Thanks.

@dkcas11
Copy link
Author

dkcas11 commented Feb 21, 2017

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 :))

@thenopen
Copy link

thenopen commented Feb 22, 2017

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.

@WenchaoD
Copy link
Owner

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
Copy link
Owner

@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
|
|--- |

@dkcas11
Copy link
Author

dkcas11 commented Feb 22, 2017

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

@dkcas11
Copy link
Author

dkcas11 commented Feb 22, 2017

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!

@WenchaoD
Copy link
Owner

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.

@dkcas11
Copy link
Author

dkcas11 commented Feb 24, 2017

@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

@WenchaoD
Copy link
Owner

@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

@dkcas11
Copy link
Author

dkcas11 commented Feb 28, 2017

@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..

@Saleh-At
Copy link

Saleh-At commented Nov 20, 2017

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
}`

@alcalyx
Copy link

alcalyx commented May 12, 2019

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?

@sebanoidze
Copy link

sebanoidze commented Jan 23, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants