美文网首页
滑动选择器

滑动选择器

作者: 轻云绿原 | 来源:发表于2019-06-26 09:18 被阅读0次

    PPFSelectViewDemo

    效果

    PPFSelectView

    引用

    pod 'PPFSelectView', '~> 0.1.0'
    

    怎么用

    let l = PPFSelectView(color: UIColor.red, itemWidthRate: 0.2,itemHeight: 2)
    l.frame.size = CGSize(width: 200, height: 40)
    l.setAnimationType(.type0)
    l.dataSource = self
    l.delegate = self
    view.addSubview(l)
    l.reloadDataSource()//刷新!一定要调用一下这个
    

    PPFSelectView_dataSource

    // MARK: - PPFSelectView_dataSource
    extension ViewController:PPFSelectView_dataSource {
        /// 有几个可选择对象
        func ppfSelectViewHasNumberOfItems(_ sView: PPFSelectView) -> Int {
            return 3
        }
        
        /// 当前索引要显示的View
        func ppfSelectView(_ sView: PPFSelectView, viewAtIndex index: Int) -> UIView {
            let l = UILabel()
            l.textAlignment = .center
            l.text = "\(index)"
            l.textColor = UIColor.black
            return l
        }
    }
    

    PPFSelectView_delegate

    /// 点击的回调
    extension ViewController:PPFSelectView_delegate {
        func ppfSelectView(_ sView: PPFSelectView, didSelectAtIndex index: Int) {
            print("已选中:\(index)")
        }
        func ppfSelectView(_ sView: PPFSelectView, animationDurationForBegin layer: CAShapeLayer) -> CFTimeInterval {
            return 0.3
        }
        func ppfSelectView(_ sView: PPFSelectView, animationDurationForEnd layer: CAShapeLayer) -> CFTimeInterval {
            return 0.2
        }
    }
    

    相关文章

      网友评论

          本文标题:滑动选择器

          本文链接:https://www.haomeiwen.com/subject/xxdqcctx.html