YMCirclePickerView 1.0.5

YMCirclePickerView 1.0.5

miletliyusuf 维护。



YMCirclePickerView

全定制化的水平圆环选择视图。

YMCirclePickerView

Swift Version Build Status License Carthage compatible CocoaPods Compatible
Platform PRs Welcome

需求

  • iOS 9.0+
  • Xcode 11+
  • Swift 5.0+

使用

Interface Builder 使用

  • 在您的视图中添加一个空视图,并设置其类为 YMCirclePickerView 及其模块。

YMCirclePickerView-Interfacebuilder

  • 添加数据源和代理(如果需要),然后通过代码自定义 布局样式 呈现。
import YMCirclePickerView

@IBOutlet private weak var circlePickerView: YMCirclePickerView!

circlePickerView.delegate = self
circlePickerView.dataSource = self
circlePickerView.presentation = YMCirclePickerViewPresentation(
   layoutPresentation: YMCirclePickerViewLayoutPresentation(
   	itemSize: CGSize(width: 100.0, height: 100.0),
   	unselectedItemSize: CGSize(width: 60.0, height: 60.0),
   	spacing: 5.0,
   	initialIndex: 3
   ),
   stylePresentation: YMCirclePickerViewStylePresentation(
   	selectionColor: .red,
   	selectionLineWidth: 4.0,
   	titleLabelDistance: 3.0
   )
)
// Or you can use the default one.
circlePickerView.presentation = .default

代码使用

它就像界面构建器实现一样简单。按照以下代码进行操作。

let circlePickerView = YMCirclePickerView()
circlePickerView.backgroundColor = .red
circlePickerView.dataSource = self
circlePickerView.presentation = YMCirclePickerViewPresentation(
   layoutPresentation: YMCirclePickerViewLayoutPresentation(
   	itemSize: CGSize(width: 75.0, height: 75.0),
   	unselectedItemSize: CGSize(width: 30.0, height: 30.0),
   	spacing: 15.0
   ),
   stylePresentation: YMCirclePickerViewStylePresentation(
   	selectionColor: .clear,
   	selectionLineWidth: 3.0,
   	titleLabelFont: .systemFont(ofSize: 12.0, weight: .thin),
   	titleLabelTextColor: .white,
   	titleLabelDistance: 3.0
   )
)
stackView.addArrangedSubview(circlePickerView)

数据源和代理方法

  • 使用方法

您的数据源类必须继承自YMCirclePickerModel。模型类的简单示例

class ExampleCirclePickerModel: YMCirclePickerModel {

    override init() {

        super.init()
    }

    convenience init(image: UIImage, title: String) {

        self.init()
        self.image = image
        self.title = title
    }
}

// Use your custom class to conform data source like below

func ymCirclePickerView(ymCirclePickerView: YMCirclePickerView, itemForIndex index: Int) -> YMCirclePickerModel? {

	let model = data[index] as ExampleCirclePickerModel
	return model
}
  • 数据源方法
func ymCirclePickerView(ymCirclePickerView: YMCirclePickerView, itemForIndex index: Int) -> YMCirclePickerModel?
func ymCirclePickerViewNumberOfItemsInPicker(ymCirclePickerView: YMCirclePickerView) -> Int
  • 代理方法
func ymCirclePickerView(ymCirclePickerView: YMCirclePickerView, didSelectItemAt index: Int)

安装

CocoaPods

要在项目中使用YMCirclePickerView,请将以下'Podfile'添加到您的项目中

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

pod 'YMCirclePickerView'

然后运行

pod install

Carthage

查看Carthage文档了解如何添加安装。YMCirclePickerView框架已经配置了共享方案。

Carthage 安装

您可以使用以下命令使用 Homebrew 安装 Carthage

$ brew update
$ brew install carthage

要使用 Carthage 将 YMCirclePickerView 集成到您的 Xcode 项目中,请在您的 Cartfile 中指定它

github "miletliyusuf/YMCirclePickerView"

TODO

  • 选定的图像嵌入

元数据

Yusuf Miletli – Linkedin, [邮箱地址去除保护]

根据MIT许可协议分发。更多信息请参阅LICENSE文件。

https://github.com/miletliyusuf/YMCirclePickerView