I need to maintain each menu text spaces (leading + trailing) value with 10-15 pixels. And only selected row text color should be white, Otherwise rest of things are should be white withAlphaComponent value 0.4. It's all need to done with using iCarousel.
Initially I was tried to achieve using like https://github.com/hightower/HTHorizontalSelectionList in my current working project which is constructing on Swift 4.1 version.
Unfortunately I can't achieve using HTHorizontalSelectionList, because In my case horizontal selection indicator should be centered. Only selected menus were moving when click or scrolling it. So that's the reason I shifted with iCarousel. It's almost I reached 90% of work except that couple of requirements.
Here below what I tried it on iCarousel,
carouselView.delegate = self
carouselView.dataSource = self
carouselView.type = .linear
carouselView.isPagingEnabled = true
carouselView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
carouselView.clipsToBounds = true;
carouselView.bounces = false
carouselView.decelerationRate = 0.6; //0.6;//0.885;
carouselView.reloadData()
carouselView.centerItemWhenSelected = true
carouselView .scrollToItem(at: 1, animated: false)
// MARK: iCarousel DeataSoure & Delegates
extension WCPPageViewController: iCarouselDataSource, iCarouselDelegate {
func numberOfItems(in carousel: iCarousel) -> Int {
return items.count
}
func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {
var label: UILabel
label = UILabel(frame: CGRect (x: 0, y: 0, width: 165, height: 80))
label.backgroundColor = .clear
label.textAlignment = .center
label.font = UIFont.WCPMontserratBold(size: 40)
label.tag = 1
label.textColor = UIColor.white
label.text = "\(items[index])"
return label
}
func carousel(_ carousel: iCarousel, didSelectItemAt index: Int) {
redirectToOtherPageControllerClass(curentIndex: CGFloat(index))
if currentIndex == 0 {
updateTeamSwitchBtnLEadingAnchorValue(leadingValue: 10)
}
else
{
updateTeamSwitchBtnLEadingAnchorValue(leadingValue: -50)
}
}
func carouselCurrentItemIndexDidChange(_ carousel: iCarousel) {
redirectToOtherPageControllerClass(curentIndex: CGFloat(carousel.currentItemIndex))
if carousel.currentItemIndex == 0 {
updateTeamSwitchBtnLEadingAnchorValue(leadingValue: 10)
}
else
{
updateTeamSwitchBtnLEadingAnchorValue(leadingValue: -50)
}
}
func carousel(_ carousel: iCarousel, itemTransformForOffset offset: CGFloat, baseTransform transform: CATransform3D) -> CATransform3D {
//implement 'flip3D' style carousel
let transformCopy = CATransform3DRotate(transform, CGFloat(.pi / 8.0), 0.0, 0.5, 0.0)
return CATransform3DTranslate (transformCopy, 0, 0, offset * carousel.itemWidth)
}
func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
switch (option) {
case .wrap:
return 0
case .fadeMin:
return -0.4//-1.5
case .fadeRange:
return 1.0
case .visibleItems:
return 3.0
case .fadeMax:
return 0.4//1.0
case .spacing:
return 0.9
default:
return value
}
}}
I have tried to adjust values on this datasource, func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat - for ".spacing:" maintain 10 - 15 pixels in between each menu text's.
And also I have adjusted ".fadeMin:, .fadeRange: and .fadeMax:" for selected row text color should be white and rest of menu's text color "white withAlphaComponent value 0.4". But the output not came what I expected.
Edited : Just now, I achieved .fadeMin:, .fadeRange: and .fadeMax: properties with the help of reading this post - How can we change the fade color in iCarousel?
Now it's working the selected row and others what I expected.
Still I'm surfing to achieve .Spacing property between menu text's.
You can possibly Try like this: