SmoothPicker 1.1.3

SmoothPicker 1.1.3

Ahmed Nasser维护。



  • 作者:
  • AVAVaas

SmoothPicker

Version License Platform

用于创建具有自定义视图的水平iOS选择器的自定义组件

Alt Text Alt Text Alt Text

示例

要运行示例项目,请首先克隆仓库,然后在示例目录中运行pod install

安装

SmoothPicker可通过CocoaPods获取。要安装它,只需将以下行添加到Podfile中即可。

pod 'SmoothPicker'

用法

可以通过storyboard或frame创建视图。

class ViewController{
   @IBOutlet weak var pickerView: SmoothPickerView!
    
    var i = 0
    var views = [UIView]()
    override func viewDidLoad() {
        super.viewDidLoad()
        for _ in 1..<11 {
            let view = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
            view.backgroundColor = UIColor.gray
            views.append(view)
        }
        
        pickerView.firstselectedItem = 2 // you can also set the first selected item at launch 

    }
    func didSelectIndex(index: Int) {
        print("SelectedIndex \(index)")
    }   
    func numberOfItems() -> Int {
        return 10
    }
    
    func itemForIndex(index: Int) -> UIView {
        return views[index]
    }
    @IBAction func navigateNext(_ sender: Any) {
        pickerView.navigate(direction: .next)
    }
    @IBAction func navigatePervious(_ sender: Any) {
        pickerView.navigate(direction: .pervious)
    }
}

数据源

func numberOfItems() -> Int //number of items to display
func itemForIndex(index:Int) -> UIView // retrun the view per item just make sure it can calculate it's frame correctly 

委托

 func didSelectIndex(index:Int,view:UIView) // the selected item  

导航

//The default navigation is swipe you can in addtion set navigation to some button 
public enum Direction {
    case  next
    case  pervious
}
public func navigate(direction :Direction)

选择

open var firstselectedItem = 0 // to set the first selected item at intilization 0 is the default 

自定义

Alt Text

// you can choose between the selection styles available 
// a new styles and layouts are upcoming 
public enum SelectionStyle {
    case scale
    case colored
}
SmoothPickerConfiguration.setSelectionStyle(selectionStyle: .scale) // scale is deafult default 
static func setColors(selectedColor:UIColor,dimmedColor:UIColor) // for colred selection style black and gray is default
@objc open func setSmoothSelected(_ selected : Bool) // you can ovveride it in your view it gives you the. current state of your view 

作者

许可证

SmoothPicker 在 MIT 许可证下可用。更多信息请查看 LICENSE 文件。

感谢这个教程,它非常有帮助 https://medium.com/@shaibalassiano/tutorial-horizontal-uicollectionview-with-paging-9421b479ee94