/Sheeter

A DropDownSheet view & ActionSheet view with Swift.

Primary LanguageSwift

Sheeter

A DropDownSheet view & ActionSheet view with Swift.

要求

  • Xcode 8.3+
  • Swift 3.2+
  • iOS 9.0+

介绍

SheeterDropDown
  • 这个控件有点类似于UIKit里的UIPopoverController(已被废弃),它可以实现基于一个sourceView的任意位置的显示,是基于UIViewController的。
  • SheeterDropDown采用了类似的设计方式,但实现和使用比较简单。
  • 用法:
  1. 默认的列表样式

DropDown Default

Sheeter.dropDown(from: sender, items: [
	"Drop Down Item1",
	"Drop Down Item2",
	"Drop Down Item3"
]) 
// 这里是点击回调
{ (selected) in
	print(selected)
}
  1. 自定义view(viewController)样式

DropDown Custom

Sheeter.dropDown(from: sender, customView: xxx)
SheeterActionSheet
  • 显而易见的,这个控件和UIKit里的UIAlertController设置style为.actionSheet后是一模一样的。
  1. 默认的列表样式

ActionSheet Default

Sheeter.actionSheet(items: [
	"Action Sheet Item1",
	"Action Sheet Item2"
])
// 回调
{ (selected) in
	print(selected)
}
  1. 自定义view(viewController)样式

ActionSheet Custom

// 使用
Sheeter.dropDown(from: sender, customView: actionCollectionVC.view)

// 自定义view的controller
fileprivate var actionCollectionVC: ActionCollectionVC{
	let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ActionCollectionVC") as! ActionCollectionVC
	vc.view.frame = CGRect(origin: .zero, size: CGSize(width: view.bounds.width, height: 100))
	vc.collectionView?.delegate = self
	return vc
}

// 代理方法
extension ViewController: UICollectionViewDelegate{
	func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
		print("You clicked Action Item \(indexPath.item)")
	}
}

Carthage

  • 目前该控件库已上传到github上,支持Carthage编译
  • 用法

1.在你的Cartfile中加入 github "BackWorld/Sheeter" "master"

2.在终端执行carthage update

3.将Carthage/Build/iOS目录下的Sheeter.framework拖到你的项目中

4.在使用的swift文件中import Sheeter即可

简书

https://www.jianshu.com/p/5e47cefb01f3

iPhoneX

iPhoneX适配

如果对你有帮助,别忘了点个赞和关注~