A lightweight, swift library for displaying popover.
// Present the view controller using the popover style.
myPopooverViewController.pop.isNeedPopover = true
// Get the popover presentation controller and configure it.
myPopooverViewController.pop.popoverPresentationController?.sourceView = sender
myPopooverViewController.pop.popoverPresentationController?.sourceRect = sender.bounds
myPopooverViewController.pop.popoverPresentationController?.arrowDirection = .up// Present the view controller using the popover style.
myPopooverViewController.modalPresentationStyle = .popover
present(myPopooverViewController, animated: true, completion: nil)
// Get the popover presentation controller and configure it.
let presentationController = myPopooverViewController.popoverPresentationController
presentationController?.sourceView = myView
presentationController?.sourceRect = sourceRectAs you see, so esay, just like system
- Init your model(PureTitleModel or NormalModel)
let sortByDate = PureTitleModel(title: "按时间排序")
let sortBySize = PureTitleModel(title: "按大小排序")
let edit = NormalModel(iconName: "ic_note_edit", description: "编辑")
let delete = NormalModel(iconName: "ic_note_delete", description: "删除")- Init PopoverTableViewController
let vc = PopoverTableViewController(items: [sortByDate, sortBySize])
vc.pop.isNeedPopover = true
vc.pop.popoverPresentationController?.barButtonItem = sender
vc.pop.popoverPresentationController?.arrowPointY = self.navigationController?.navigationBar.frame.maxY
vc.delegate = self
present(vc, animated: true, completion: nil)- Or custom your own model(PopoverCellConfiguration)
/// Custom
struct CustomModel: PopoverCellConfiguration {
public var width: CGFloat {
let cell = AjustFontPopoverCell()
config(cell: cell)
let width = cell.systemLayoutSizeFitting(UILayoutFittingCompressedSize).width
return width
}
public var resuable: PopoverCellResuable.Type {
return AjustFontPopoverCell.self
}
public func config(cell: UITableViewCell) {
guard let cell = cell as? AjustFontPopoverCell else {
return
}
// config delegate...
}
}public enum PopoverConfiguration.Animation {
case scale
case alpha
}arrowSize = CGSize(width: 12, height: 7)cornerRadius = CGFloat(4)animationDuration = TimeInterval(0.25)backgroundColor = UIColor.whitedimmingViewColor = UIColor.black.withAlphaComponent(0.35)showDimmingView = trueanimation: Animation = .scale
- iOS 8.0+
- Xcode 8.0+
- Swift4
Create a Cartfile that lists the framework. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/PopoverKit.framework to an iOS project.
github "ZionChang/PopoverKit"Run carthage update to build the framework and drag the built PopoverKit.framework into your Xcode project.
To get the full benefits import PopoverKit
import PopoverKitYou can use CocoaPods to install PopoverKit by adding it to your Podfile:
platform :ios, '8.0'
use_frameworks!
pod 'PopoverKit', '~> 0.2.0'Then, run the following command:
$ pod install- Download and drop
PopoverKitin your project. - Congratulations!
- [] Ability to customize animation
PopoverKit is licensed under the MIT License, please see the LICENSE file.