telember / ShelfView-iOS

iOS custom view to display books on shelf

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ShelfView (iOS)

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

Requirements

  • iOS 8.0+
  • Swift 3

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.

Example

import ShelfView

class ViewController: UIViewController, ShelfViewDelegate {

var shelfView:ShelfView!
var bookModel = [BookModel] ()

override func viewDidLoad() {

  super.viewDidLoad()

  shelfView = ShelfView(frame: CGRect(x: 0, y: 0, width: 375, height: 647))        
  bookModel.append(
    BookModel.init(bookCoverSource: "http://www.aidanf.net/images/learn-swift/cover-web.png", 
    bookId: "0", 
    bookTitle: "Learn Swift"))
  
  shelfView.loadData(bookModel: bookModel, 
    bookSource: ShelfView.BOOK_SOURCE_URL)       

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

func onBookClicked(_ shelfView: ShelfView, position: Int, bookId: String, bookTitle: String) {
  print("I just clicked \(bookTitle) with bookId \(bookId) @ position \(position)")
}

}

Updating ShelfView data

bookModel.append(
  BookModel.init(bookCoverSource: "https://www.packtpub.com/sites/default/files/9781785288197.png", 
  bookId: "1", 
  bookTitle: "Learning iOS UI Development"))
shelfView.updateData(bookModel: self.bookModel)

Resizing ShelfView

shelfView.resize(width: 647, height: 370, bookModel: self.bookModel)

Loading book covers from other sources

  • iPhone/iPad document directory
bookModel.append(
  BookModel.init(bookCoverSource: "bookCover.png", 
  bookId: "0", 
  bookTitle: "Learn Swift"))
  
shelfView.loadData(bookModel: bookModel, 
  bookSource: ShelfView.BOOK_SOURCE_DEVICE_DOCUMENTS)
  • iPhone/iPad library directory
bookModel.append(
  BookModel.init(bookCoverSource: "bookCover.png", 
  bookId: "0", 
  bookTitle: "Learn Swift"))      
  
shelfView.loadData(bookModel: bookModel, 
  bookSource: ShelfView.BOOK_SOURCE_DEVICE_LIBRARY)
  • iPhone/iPad cache directory
bookModel.append(
  BookModel.init(bookCoverSource: "bookCover.png", 
  bookId: "0", 
  bookTitle: "Learn Swift"))
  
shelfView.loadData(bookModel: bookModel, 
  bookSource: ShelfView.BOOK_SOURCE_DEVICE_CACHE)
  • Directly from your project's source code
bookModel.append(
  BookModel.init(bookCoverSource: "bookCover.png", 
  bookId: "0", 
  bookTitle: "Learn Swift"))
  
shelfView.loadData(bookModel: bookModel, 
  bookSource: ShelfView.BOOK_SOURCE_RAW)

License

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

Author

Adeyinka Adediji (tdscientist@gmail.com)

Contributions & Bug Reporting

tdscientist@gmail.com

Credits

About

iOS custom view to display books on shelf

License:MIT License


Languages

Language:Swift 95.3%Language:Ruby 4.7%