FSPagerView
FSPagerView copied to clipboard
Register custom cell
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 :)
Hi @dkcas11 Can you provide a demo project link which reproduces and demonstrates your issue?
Thanks.
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 :))
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.
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.
@dkcas11 If you cannot find 0.2.0
in CocoaPods, probably you should try pod repo update
.
|
Yea, i forgot i had removed it again... D'oh.. :)
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!
Hi @dkcas11
- I don't quite understand what does this mean:
normal square cells are still behind my custom cell
- To keep the shadow, maybe you should try mask the
imageView
or thecontentView
of the cell instead.
@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 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 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..
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
}`
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 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.