Skip to content

Instantly share code, notes, and snippets.

View dejanskledar's full-sized avatar

Dejan Skledar dejanskledar

View GitHub Profile
@dejanskledar
dejanskledar / CollectionViewCenterLayout.swift
Created May 10, 2018 07:23
This is a sample of a Centered CollectionView Flow Layout
class CollectionViewRow {
...
var rowWidth: CGFloat {
return attributes.reduce(0, { result, attribute -> CGFloat in
return result + attribute.frame.width
}) + CGFloat(attributes.count - 1) * spacing
}
func centerLayout(collectionViewWidth: CGFloat) {
@dejanskledar
dejanskledar / CollectionViewCenterLayout.swift
Last active May 10, 2018 07:22
This is a sample of a Centered CollectionView Flow Layout
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
...
var rows = [CollectionViewRow]()
var currentRowY: CGFloat = -1
for attribute in attributes {
if currentRowY != attribute.frame.origin.y {
currentRowY = attribute.frame.origin.y
rows.append(CollectionViewRow(spacing: 10))
}
@dejanskledar
dejanskledar / CollectionViewCenterLayout.swift
Created May 10, 2018 07:20
This is a sample of a Centered CollectionView Flow Layout
class CollectionViewRow {
var attributes = [UICollectionViewLayoutAttributes]()
var spacing: CGFloat = 0
init(spacing: CGFloat) {
self.spacing = spacing
}
func add(attribute: UICollectionViewLayoutAttributes) {
attributes.append(attribute)
@dejanskledar
dejanskledar / CollectionViewCenterLayout.swift
Last active May 10, 2018 07:21
This is a sample of a Centered CollectionView Flow Layout
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
guard let attributes = super.layoutAttributesForElements(in: rect) else {
return nil
}
...
}
@dejanskledar
dejanskledar / ViewController.swift
Created May 10, 2018 07:16
This is a sample of a Centered CollectionView Flow Layout
let layout = UICollectionViewFlowLayout()
layout.estimatedItemSize = CGSize(width: 140, height: 40)
collectionView.collectionViewLayout = layout
@dejanskledar
dejanskledar / PDFKit.swift
Created January 31, 2018 19:08
PDFKit Example
guard let data = self.pdfDocument.dataRepresentation() else { return }
let activityController = UIActivityViewController(activityItems: [data], applicationActivities: nil)
self.present(activityController, animated: true, completion: nil)
@dejanskledar
dejanskledar / PDFKit.swift
Created January 31, 2018 19:07
PDFKit Example
open func dataRepresentation() -> Data?
@dejanskledar
dejanskledar / PDFKit.swift
Created January 31, 2018 18:45
PDFKit Example
open func insert(_ page: PDFPage, at index: Int)
open func removePage(at index: Int)
open func exchangePage(at indexA: Int, withPageAt indexB: Int)
@dejanskledar
dejanskledar / PDFKit.swift
Last active February 2, 2018 13:25
Introducing PDFKit
guard let url = URL(string:"www.your_pdf_url.com") else { return }
let pdfView = PDFView(frame: view.frame)
let pdfDocument = PDFDocument(url: url)
pdfView.document = pdfDocument
view.addSubview(pdfView)
UIView.animateKeyframes(withDuration: 5.0, delay: 0, options: [.calculationModeCubic], animations: {
// Add animations
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1.0/5.0, animations: {
view.frame.origin.x += 200
})
UIView.addKeyframe(withRelativeStartTime: 1.0/5.0, relativeDuration: 1.0/5.0, animations: {
view.backgroundColor = .green
})
UIView.addKeyframe(withRelativeStartTime: 2.0/5.0, relativeDuration: 1.0/5.0, animations: {
view.frame.origin.y += 200