Skip to content

Instantly share code, notes, and snippets.

View harrysummers's full-sized avatar

Harry Summers harrysummers

  • EBSCO Ind.
  • Birmingham AL
View GitHub Profile
@harrysummers
harrysummers / gist:430bc09387f45c3e5801bd6312852fb1
Created May 19, 2018 19:36
Get currently active view controller
fileprivate func getShowingViewController(_ rootViewController: UIViewController) -> UIViewController? {
var isRoot = false
var showViewController: UIViewController? = rootViewController
while (!isRoot) {
if let tempViewController = showViewController?.presentedViewController {
showViewController = tempViewController
} else {
isRoot = true
}
}
@harrysummers
harrysummers / gist:33cb567be3c4f9008833456f4b95db34
Created May 18, 2018 21:17
Assigning the viewController property
override func viewDidLoad() {
super.viewDidLoad()
addAlbumView.viewController = self
}
@harrysummers
harrysummers / gist:763c761b3c20380b7cd9224291e196f1
Created May 18, 2018 21:15
UIView property in View Controller
let addAlbumView: AddAlbumView = {
let view = AddAlbumView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
@harrysummers
harrysummers / gist:a5d7c503ef04bba329f8c99ba6b5ccdc
Created May 18, 2018 21:13
View controller property in UIView
weak var viewController: UIViewController? {
didSet {
setupViewController()
}
}
import UIKit
class AddAlbumView: UIView {
var albumArt: UIImageView = {
var imageView = UIImageView()
imageView.contentMode = .scaleAspectFill
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.backgroundColor = UIColor.CustomColors.spotifyDark
return imageView
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let gif = gifs[indexPath.row]
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath) as! GifCollectionViewCell
cell.gifView.loadGif(name: gif)
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
@harrysummers
harrysummers / gist:6bc5d52897feca8afd24271c5346051d
Created May 17, 2018 20:17
UICollectionView programmatically
lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.itemSize = CGSize(width: 140, height: 250)
layout.scrollDirection = .horizontal
let collection = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
collection.translatesAutoresizingMaskIntoConstraints = false
collection.register(GifCollectionViewCell.self, forCellWithReuseIdentifier: cellId)
collection.backgroundColor = UIColor.CustomColors.spotifyDark
collection.bounces = true
collection.alwaysBounceHorizontal = true
import UIKit
import SpotifyLogin
class SettingsViewController: UIViewController {
var scrollView: UIScrollView = {
var scroll = UIScrollView()
scroll.translatesAutoresizingMaskIntoConstraints = false
scroll.bounces = true
scroll.isScrollEnabled = true
@harrysummers
harrysummers / gist:4a1af1d488d2dd4928095b5ab803d9c1
Created May 15, 2018 21:46
Sliding Left Transition Animation
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView
let toView = transitionContext.view(forKey: .to)!
let fromView = transitionContext.view(forKey: .from)!
let slideTransform = CGAffineTransform(translationX: toView.frame.width, y: 0)
toView.transform = slideTransform
let finalFrame = CGRect(x: -fromView.frame.width, y: 0, width: fromView.frame.width, height: fromView.frame.height)
public override func prepareForDeletion() {
if let artist = artist {
let albums = artist.albums
if albums == nil || albums?.count == 1 {
managedObjectContext?.delete(artist)
}
}
}