I'm creating an iOS app with Swift and am using iCarousel from GitHub (installed via cocoapods) and I'm not sure what I'm doing wrong, but I can't seem to get iCarouselOptions I set to have any effect...
What I want to do is simply change the spacing of the UIViews in my carousel (They are too close together and overlapping, which I don't want).
Here is my code:
import UIKit
import iCarousel
class MiniGamesViewController: UIViewController, iCarouselDelegate, iCarouselDataSource {
//Objects
@IBOutlet weak var leaveMinigamesButton: UIButton!
//Variables
var carouselHeight : CGFloat!
var selectionBallSize : CGFloat!
override func viewDidLoad() {
super.viewDidLoad()
leaveMinigamesButton.layer.zPosition = 3
carouselHeight = self.view.frame.size.height - 200
selectionBallSize = self.view.frame.size.width * 0.65
let carousel = iCarousel(frame: CGRect(
x: 0,
y: 100,
width: self.view.frame.size.width,
height: carouselHeight))
carousel.perspective = -0.005
carousel.centerItemWhenSelected = true
carousel.decelerationRate = 0.9
carousel.viewpointOffset = CGSize(width: 0, height: 0) //-selectionBallSize * 1.2
carousel.dataSource = self
carousel.type = .rotary
view.addSubview(carousel)
}
override func viewDidAppear(_ animated: Bool) {
setNeedsStatusBarAppearanceUpdate()
}
//This is how many items there will be in my rotary iCarousel
func numberOfItems(in carousel: iCarousel) -> Int {
return 6
}
//This defines each item or 'cell' in the iCarousel
func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {
let imageView: UIImageView
if view != nil {
imageView = view as! UIImageView
} else {
imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: selectionBallSize, height: selectionBallSize))
}
imageView.image = UIImage(named: "orbCyan")
return imageView
}
func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
switch (option) {
case .spacing: return value * 2
case .radius: return 200
case .fadeMinAlpha: return 0.5
default: return value
}
}
}
Specifically the very bottom of my code is where the customization is supposed to take effect, but it doesn't seem to be making any changes when I run the app. At the moment, I'm only concerned with trying to space the UIViews in the carousel to be further apart.
Am I putting the iCarouselOptions function in the right place? Is it even being 'called' at all?
Thanks for your help!
Wouldn't you know it, as soon as I posted this question I found the issue haha (after a day of trying everything). Turns out I was missing the simple line:
underneath:
That totally did the trick and it works now lol. I need a fresh set of eyes :P