Ios 如何使用iCarousel维护菜单之间的空格并为选定和未选定状态设置不同的文本颜色?

Ios 如何使用iCarousel维护菜单之间的空格并为选定和未选定状态设置不同的文本颜色?,ios,swift,icarousel,Ios,Swift,Icarousel,我需要将每个菜单文本空格(前导+尾随)值保持为10-15像素。并且只有选定的行文本颜色应为白色,否则其余内容应为白色,AlphaComponent值为0.4。这一切都需要使用iCarousel来完成 最初,我试图在我当前的工作项目中实现使用like,该项目正在Swift 4.1版本上构建 不幸的是,我无法使用HTHorizontalSelectionList实现,因为在我的例子中,水平选择指示器应该居中。单击或滚动菜单时,只有选定的菜单在移动。这就是我和伊卡鲁塞尔调换的原因。除了这两个要求,我几

我需要将每个菜单文本空格(前导+尾随)值保持为10-15像素。并且只有选定的行文本颜色应为白色,否则其余内容应为白色,AlphaComponent值为0.4。这一切都需要使用iCarousel来完成

最初,我试图在我当前的工作项目中实现使用like,该项目正在Swift 4.1版本上构建

不幸的是,我无法使用HTHorizontalSelectionList实现,因为在我的例子中,水平选择指示器应该居中。单击或滚动菜单时,只有选定的菜单在移动。这就是我和伊卡鲁塞尔调换的原因。除了这两个要求,我几乎完成了90%的工作

下面是我在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)
//马克:伊卡鲁塞尔·迪塔苏尔和代表

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
    }
}}
我已尝试调整此数据源func carousel(uousel:iCarousel,valueFor option:icarouseoption,默认值为:cgloat)->cgloat-for“.spacing:”在每个菜单文本之间保持10-15像素

我还调整了“.fadeMin:,.faderage:和.fadeMax:”所选行的文本颜色应为白色,菜单的其余文本颜色“白色,AlphaComponent值为0.4”。但结果并没有达到我的预期

编辑: 刚才,在阅读这篇文章的帮助下,我实现了.fadeMin:,.faderage:和.fadeMax:属性-

现在它正在处理所选的行和其他我所期望的行


我仍然在冲浪,以实现菜单文本之间的。间距属性。

您可以这样尝试:

   func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
    switch (option) {
        case .spacing: return 8 // 8 points spacing
        default: return value
    }
}