iOS custom view to display books on shelf

Overview

ShelfView (iOS)

iOS custom view to display books on shelf (Android version is available here)

Requirements

  • iOS 10.0+
  • Swift 4.2

Installation

ShelfView is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ShelfView'

Note

Because of book covers whose URLs are http, update your info.plist as follows:

  • add App Transport Security Settings to the list
  • add Allow Arbitrary Loads to the security settings added above; set it to YES.

Plain Shelf

import ShelfView

class PlainShelfController: UIViewController, PlainShelfViewDelegate {
    var shelfView: PlainShelfView!

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let books = [
            BookModel(bookCoverSource: "https://files.kerching.raywenderlich.com/covers/d5693015-46b6-44f8-bf7b-7a222b28d9fe.png",
                      bookId: "0",
                      bookTitle: "Realm: Building Modern Swift Apps with Realm"),
            BookModel(bookCoverSource: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTYEkCQ_wu8HoGJzzs_gUH_FVusgI2RhntBKQ-WkmqnDJZnriwY6Q",
                      bookId: "1",
                      bookTitle: "iOS 10 by Tutorials: Learning the new iOS APIs with Swift 3")
        ]        
        
        shelfView = PlainShelfView(frame: CGRect(x: 0, y: 0, width: 350, height: 500),
                                   bookModel: books, bookSource: PlainShelfView.BOOK_SOURCE_URL)

        shelfView.delegate = self
        self.view.addSubview(shelfView)
    }

    func onBookClicked(_ shelfView: PlainShelfView, index: Int, bookId: String, bookTitle: String) {
        print("I just clicked \"\(bookTitle)\" with bookId \(bookId), at index \(index)")
    }

}

Section Shelf

import ShelfView

class SectionShelfController: UIViewController, SectionShelfViewDelegate {
    var shelfView: SectionShelfView!

    override func viewDidLoad() {
        super.viewDidLoad()

        let books = [
            BookModel(bookCoverSource: "https://files.kerching.raywenderlich.com/covers/d5693015-46b6-44f8-bf7b-7a222b28d9fe.png",
                      bookId: "0",
                      bookTitle: "Realm: Building Modern Swift Apps with Realm"),
            BookModel(bookCoverSource: "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTYEkCQ_wu8HoGJzzs_gUH_FVusgI2RhntBKQ-WkmqnDJZnriwY6Q",
                      bookId: "1",
                      bookTitle: "iOS 10 by Tutorials: Learning the new iOS APIs with Swift 3")
        ]
        let bookModelSectionArray = [BookModelSection(sectionName: "RAYWENDERLICH",
                                                      sectionId: "0",
                                                      sectionBooks: books)]

        shelfView = SectionShelfView(frame: CGRect(x: 0, y: 0, width: 350, height: 500),
                                     bookModelSection: bookModelSectionArray,
                                     bookSource: SectionShelfView.BOOK_SOURCE_URL)

        shelfView.delegate = self
        self.view.addSubview(shelfView)
    }

    func onBookClicked(_ shelfView: SectionShelfView, section: Int, index: Int,
                       sectionId: String, sectionTitle: String, bookId: String,
                       bookTitle: String) {
        print("I just clicked \"\(bookTitle)\" with bookId \(bookId), at index \(index). Section details --> section \(section), sectionId \(sectionId), sectionTitle \(sectionTitle)")
    }

}

Add more books to ShelfView

  • Plain Shelf
addBooks(bookModel: [BookModel])
  • Section Shelf
addBooks(bookModelSection: [BookModelSection])

Reload books on ShelfView

  • Plain Shelf
reloadBooks(bookModel: [BookModel])
  • Section Shelf
reloadBooks(bookModelSection: [BookModelSection])

Loading book covers from other sources

  • iPhone/iPad document directory
let books = [
    BookModel(bookCoverSource: "bookcover0.png", bookId: "0", bookTitle: "Book Title 0"),
    BookModel(bookCoverSource: "bookcover1.png", bookId: "1", bookTitle: "Book Title 1")
        ]
shelfView = PlainShelfView(frame: CGRect(x: 0, y: 0, width: 350, height: 500),
                           bookModel: books, bookSource: PlainShelfView.BOOK_SOURCE_DEVICE_DOCUMENTS)
  • iPhone/iPad library directory
let books = [
    BookModel(bookCoverSource: "bookcover0.png", bookId: "0", bookTitle: "Book Title 0"),
    BookModel(bookCoverSource: "bookcover1.png", bookId: "1", bookTitle: "Book Title 1")
        ]
shelfView = PlainShelfView(frame: CGRect(x: 0, y: 0, width: 350, height: 500),
                           bookModel: books, bookSource: PlainShelfView.BOOK_SOURCE_DEVICE_LIBRARY)
  • iPhone/iPad cache directory
let books = [
    BookModel(bookCoverSource: "bookcover0.png", bookId: "0", bookTitle: "Book Title 0"),
    BookModel(bookCoverSource: "bookcover1.png", bookId: "1", bookTitle: "Book Title 1")
        ]
shelfView = PlainShelfView(frame: CGRect(x: 0, y: 0, width: 350, height: 500),
                           bookModel: books, bookSource: PlainShelfView.BOOK_SOURCE_DEVICE_CACHE)
  • Directly from your project's source code
let books = [
    BookModel(bookCoverSource: "bookcover0.png", bookId: "0", bookTitle: "Book Title 0"),
    BookModel(bookCoverSource: "bookcover1.png", bookId: "1", bookTitle: "Book Title 1")
        ]
shelfView = PlainShelfView(frame: CGRect(x: 0, y: 0, width: 350, height: 500),
                           bookModel: books, bookSource: PlainShelfView.BOOK_SOURCE_RAW)

License

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

Author

Adeyinka Adediji ([email protected])

Contributions & Bug Reporting

[email protected]

Credits

You might also like...
iOS custom view to display books on shelf
iOS custom view to display books on shelf

ShelfView (iOS) iOS custom view to display books on shelf (Android version is available here) Requirements iOS 10.0+ Swift 4.2 Installation ShelfView

Use any custom view as custom callout view for MKMapView with cool animations. Use any image as annotation view.
Use any custom view as custom callout view for MKMapView with cool animations. Use any image as annotation view.

MapViewPlus About MapViewPlus gives you the missing methods of MapKit which are: imageForAnnotation and calloutViewForAnnotationView delegate methods.

A simple iOS app similar to iTunes where you can view details of your favorite movies, songs and audio books.
A simple iOS app similar to iTunes where you can view details of your favorite movies, songs and audio books.

Popcorn Adventure This is an iOS app developed by Arthur Tristan M. Ramos who has taken the Appetiser iOS Coding Challenge. Design Pattern The design

Library that holds multiple books loaded from json in a scroll view where each book can be tapped on, favorited, rated, and opened to read
Library that holds multiple books loaded from json in a scroll view where each book can be tapped on, favorited, rated, and opened to read

Library that holds multiple books loaded from json in a scroll view where each book can be tapped on, favorited, rated, and opened to read. If a book is a favorite, an orange star appears on the book's cover. Page number, favorites, and ratings are saved for each session of the app.

Reading List is an iOS app for iPhone and iPad which helps users track and catalog the books they read
Reading List is an iOS app for iPhone and iPad which helps users track and catalog the books they read

Reading List Reading List is an iOS app for iPhone and iPad which helps users track and catalog the books they read. Reading List v2 As of version 2.0

iOS Open Source Application written in Swift. App to manage borrowed books at UFRGS using SABI.
iOS Open Source Application written in Swift. App to manage borrowed books at UFRGS using SABI.

RenovaLivrosUFRGS iOS Open Source Application written in Swift. App to manage borrowed books at UFRGS using SABI. App in portuguese, code and comments

Native iOS app built in SwiftUI, displays a collection of user's books.

Native iOS app built in SwiftUI, displays a collection of user's books.

Video mp4 record save display - How to Take , Save and Display a .mp4 Video

Technicalisto How to Take , Save and Display a .mp4 Video Add your design with v

đŸ–„ Control your display's brightness & volume on your Mac as if it was a native Apple Display
đŸ–„ Control your display's brightness & volume on your Mac as if it was a native Apple Display

đŸ–„ Control your display's brightness & volume on your Mac as if it was a native Apple Display. Use Apple Keyboard keys or custom shortcuts. Shows the native macOS OSDs.

With the Coverless App, you can discover many books of various genres
With the Coverless App, you can discover many books of various genres

Coverless NĂŁo julgue um livro pela capa: use a sinopse! Com o App Coverless, vocĂȘ pode descobrir muitos livros de vĂĄrios gĂȘneros. Salve seus livros de

The Xcode playground labs from the Develop in Swift Fundamentals and Data Collections books.
The Xcode playground labs from the Develop in Swift Fundamentals and Data Collections books.

Develop in Swift Labs A repository with the student materials from the Xcode 12 version of Develop with Swift Fundamentals This repo contains the Swif

ReadMe app is here to list all of the physical books in your personal library
ReadMe app is here to list all of the physical books in your personal library

ReadMe App The ReadMe app is here to list all of the physical books in your personal library, mark books you still have to read review books after you

Uses Firestore to remotely store books that are sorted by genre locally.
Uses Firestore to remotely store books that are sorted by genre locally.

Uses Firestore to remotely store books that are sorted by genre locally. Books can be added, removed, or edited from within the app or on Firebase.

An ongoing curated list of frameworks, books, articles, talks, screencasts, recordings, libraries, learning tutorials and resources about Swift
Quillow is an elegant book management app on the App Store that allows you to search, add and track the books you've consumed.

Quillow Quillow is an elegant book management app on the App Store that allows you to search, add and track the books you've consumed. Please use the

Bookworm - Track which books you’ve read and what you thought of them
Bookworm - Track which books you’ve read and what you thought of them

Bookworm Description: Bookworm is an app I built while following 100 Days of Swi

BookShelf - an app for cataloguing and tracking your books
BookShelf - an app for cataloguing and tracking your books

BookShelf An app for cataloguing and tracking your books. Watch the talk » Report Bug · Request Feature Table of Contents About The Project Getting St

A fully customizable container view controller to display a set of ViewControllers in a horizontal scroll view. Written in Swift.
A fully customizable container view controller to display a set of ViewControllers in a horizontal scroll view. Written in Swift.

DTPagerController This is a control for iOS written in Swift. DTPagerController is simple to use and easy to customize. Screenshots Default segmented

Owner
Adeyinka Adediji
Mobile [Android & iOS] Developer
Adeyinka Adediji
Useful SwiftUI container view's. FittingGeometry, ScrollableView, LayoutReader, PageView, UIKitView. (iOS)

Containers Also available as a part of my SwiftUI+ Collection – just add it to Xcode 13+ Useful SwiftUI container view's for additional convenience. I

SwiftUI+ 32 Dec 27, 2022
Blueprints is a collection of flow layouts that is meant to make your life easier when working with collection view flow layouts.

Blueprints is a collection of flow layouts that is meant to make your life easier when working with collection view flow layouts. It comes

Christoffer Winterkvist 982 Dec 7, 2022
BouncyLayout is a collection view layout that makes your cells bounce.

BouncyLayout is a collection view layout that makes your cells bounce. Features Pure Swift 5. Works with every UICollectionView. Horizontal and vertic

Robert-Hein Hooijmans 4.2k Jan 5, 2023
An easy-to-use Collection View Layout for card-like animation.

CarLensCollectionViewLayout An easy-to-use Collection View Layout for card-like animation ?? CarLensCollectionViewLayout was created out of the implem

Netguru 530 Dec 16, 2022
FSPagerView is an elegant Screen Slide Library. It is extremely helpful for making Banner View、Product Show、Welcome/Guide Pages、Screen/ViewController Sliders.

SWIFT OBJECTIVE-C FSPagerView is an elegant Screen Slide Library implemented primarily with UICollectionView. It is extremely helpful for making Banne

Wenchao Ding 6.7k Jan 2, 2023
UICollectionViewSplitLayout makes collection view more responsive.

UICollectionViewSplitLayout makes collection view more responsive. What's this? UICollectionViewSplitLayout is a subclass of UICollectionViewLayout. I

Yahoo! JAPAN 239 Dec 6, 2022
Declaretive UICollectionViewCompositionalLayout interface to implement complex collection view layout.

CompositionalLayoutViewController Example To run the example project, clone the repo, and run pod install from the Example directory first. Requiremen

ONEinc 19 Dec 2, 2022
Easy and type-safe iOS table and collection views in Swift.

Quick Start TL;DR? SimpleSource is a library that lets you populate and update table views and collection views with ease. It gives you fully typed cl

Squarespace 96 Dec 26, 2022
↕ VegaScroll is a lightweight animation flowlayout for UICollectionView completely written in Swift 4, compatible with iOS 11 and Xcode 9.

Made by Applikey Solutions Find this project on Dribbble Also check another flowlayout for UICollectionView: https://github.com/ApplikeySolutions/Grav

Applikey Solutions 2.8k Jan 1, 2023
A mirror of Apple's sample code for high performance collection views in iOS 15.

Building High-Performance Lists and Collection Views Improve the performance of lists and collections in your app with prefetching and image preparati

Tim Oliver 14 Nov 12, 2022