KUIPopOver is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'KUIPopOver'
For iOS 8+ projects with Carthage
github "Kofktu/KUIPopOver"
let popOverViewController = DefaultPopOverViewController()
popOverViewController.preferredContentSize = CGSize(width: 200.0, height: 300.0)
popOverViewController.popoverPresentationController?.sourceView = sender
let customView = CustomPopOverView(frame: CGRect(origin: CGPoint(x: 0.0, y: 0.0), size: CGSize(width: 200.0, height: 300.0)))
popOverViewController.view.addSubview(customView)
popOverViewController.popoverPresentationController?.sourceRect = sender.bounds
present(popOverViewController, animated: true, completion: nil)
public protocol KUIPopOverUsable {
var contentSize: CGSize { get }
var contentView: UIView { get }
var popOverBackgroundColor: UIColor? { get }
var arrowDirection: UIPopoverArrowDirection { get }
}
public func showPopover(sourceView: UIView, sourceRect: CGRect?, completion: ShowPopoverCompletion?)
public func showPopover(barButtonItem: UIBarButtonItem, completion: ShowPopoverCompletion?)
public func dismissPopover(animated: Bool, completion: DismissPopoverCompletion?)
public func showPopover(sourceView: UIView, sourceRect: CGRect?, completion: ShowPopoverCompletion?)
public func showPopoverWithNavigationController(sourceView: UIView, sourceRect: CGRect?, completion: ShowPopoverCompletion?)
public func showPopover(barButtonItem: UIBarButtonItem, completion: ShowPopoverCompletion?)
public func showPopoverWithNavigationController(barButtonItem: UIBarButtonItem, completion: ShowPopoverCompletion?)
public func dismissPopover(animated: Bool, completion: DismissPopoverCompletion?)
class CustomView: UIView, KUIPopOverUsable {
// The default size is the size of the view, and you can override it if you want to customize it.
var contentSize: CGSize {
return Size
}
}
let view = CustomView()
view.showPopover(barButtonItem: sender)
view.dismissPopover(animated: true)
view.dismissPopover(animated: true, completion: {
})
class CustomViewController: UIViewController, KUIPopOverUsable {
var contentSize: CGSize {
// PopOver preferredContentSize
}
}
let customViewController = CustomViewController()
// from senderView
customViewController.showPopover(sourceView: sender, sourceRect: sender.bounds)
// from barButtonItem
customViewController.showPopover(barButtonItem: sender)
// with NavigationController
customViewController.showPopoverWithNavigationController(sourceView: sender, sourceRect: sender.bounds)
customViewController.dismissPopover(animated: true)
customViewController.dismissPopover(animated: true, completion: {
})
Taeun Kim (kofktu), kofktu@gmail.com
KUIPopOver is available under the MIT
license. See the LICENSE
file for more info.