Git Product home page Git Product logo

fspopoverview's Introduction

FSPopoverView

Version Status Swift 5.x Platform Carthage compatible license MIT

A library to present popovers.

Demo

Custom content
List (Light)
List (Dark)
List (Custom item)
List (Horizontal layout)

Support

  • Customization
  • Arrow direction
  • Hidden Arrow
  • Custom border
  • Custom shadow
  • Custom transition animation
  • Custom list item
  • Dark mode (iOS13+)
  • Global appearance
  • Arrow direction priority
  • List appends/removes item
  • Compatible with screen rotation

Requirements

  • iOS 13+
  • Swift 5
  • Xcode 15+

Installation

CocoaPods (recommended)

pod 'FSPopoverView'
github "lifution/FSPopoverView"

Copy manually

Download or clone the repository, drag the folder FSPopoverView into your project, and tick Copy items if needed and Create groups.

Usage

  • If you need to customize the content, use FSPopoverView, implements the dataSource and return the contents.
let popoverView = FSPopoverView()
popoverView.dataSource = self
popoverView.present(fromBarItem: barItem)

// data source
extension viewController: FSPopoverViewDataSource {
    
    func backgroundView(for popoverView: FSPopoverView) -> UIView? {
        let view = UIView()
        view.backgroundColor = .yellow
        return view
    }
    
    func contentView(for popoverView: FSPopoverView) -> UIView? {
        return contentView
    }
    
    func contentSize(for popoverView: FSPopoverView) -> CGSize {
        return .init(width: 100.0, height: 100.0)
    }
    
    func containerSafeAreaInsets(for popoverView: FSPopoverView) -> UIEdgeInsets {
        return view.safeAreaInsets
    }
    
    func popoverViewShouldDismissOnTapOutside(_ popoverView: FSPopoverView) -> Bool {
        return true
    }
}
  • If you need to display a list, use FSPopoverListView, which provides FSPopoverListTextItem by default. FSPopoverListView is data-driven. Inherits FSPopoverListItem and FSPopoverListCell if you need to customize the item.
let features: [Feature] = [.copy, .message, .db, .qr, .settings]
let items: [FSPopoverListItem] = features.map { feature in
    let item = FSPopoverListTextItem()
    item.image = feature.image
    item.title = feature.title
    item.isSeparatorHidden = false
    item.selectedHandler = { item in
        guard let item = item as? FSPopoverListTextItem else {
            return
        }
        print(item.title ?? "")
    }
    item.updateLayout()
    return item
}
items.last?.isSeparatorHidden = true
let listView = FSPopoverListView()
listView.items = items
listView.present(fromRect: sender.frame.insetBy(dx: 0.0, dy: -6.0), in: view)
  • Use FSPopoverView.fs_appearance() to customize default values for popover view.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    do {
        let appearance = FSPopoverView.fs_appearance()
        appearance.showsArrow = false
        appearance.showsDimBackground = true
        ...
    }
    return true
}
  • For more information on how to use, see the example project under the repository.

License

FSPopoverView is available under the MIT license. See the LICENSE file for more info.

fspopoverview's People

Contributors

lifution avatar parmar-mehul avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.