This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func addTextToImage(text: NSString, inImage: UIImage, atPoint:CGPoint) -> UIImage{ | |
// Setup the font specific variables | |
let textColor = YOUR_COLOR | |
let textFont = YOUR_FONT | |
//Setups up the font attributes that will be later used to dictate how the text should be drawn | |
let textFontAttributes = [ | |
NSFontAttributeName: textFont, | |
NSForegroundColorAttributeName: textColor, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TodayViewController.swift | |
// LocationTodayExtension | |
// | |
// Created by Pete Smith on 24/03/2016. | |
// Copyright © 2016 Pete Smith. All rights reserved. | |
// | |
import UIKit | |
import NotificationCenter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
enum State { | |
case initial | |
case launched | |
case launchingWithLocation | |
case launchingWithoutLocation | |
case running |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// rot 13 | |
var rot13Mapped = [Character:Character]() | |
let upperCase = Array("ABCDEFGHIJKLMNOPQRSTUVWXYZ".characters) | |
let lowerCase = Array("abcdefghijklmnopqrstuvwxyz".characters) | |
for (index, _) in upperCase.enumerated() { | |
rot13Mapped[upperCase[index]] = upperCase[(index + 13) % 26] | |
rot13Mapped[lowerCase[index]] = lowerCase[(index + 13) % 26] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UITextView { | |
/** | |
Calculates if new textview height (based on content) is larger than a base height | |
- parameter baseHeight: The base or minimum height | |
- returns: The new height | |
*/ | |
func newHeight(withBaseHeight baseHeight: CGFloat) -> CGFloat { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { | |
var centerCell: UICollectionViewCell? = nil | |
// Get cell being displayed in the center of the screen | |
// Do this by getting the cell that is fully visible | |
for cell in scalingCarousel.visibleCells { | |
let cellRect = scalingCarousel.convert(cell.frame, to: nil) | |
// Get the cell that is fully visible, this will have an origin x value between 30 and 70 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
if segue.identifier == "Segue1" { | |
if let viewController1 = segue.destination as? ViewController1 { | |
self.viewController1 = viewController1 | |
} | |
} else if segue.identifier == "Segue12" { | |
if let viewController2 = segue.destination as? ViewController2 { | |
self.viewController2 = viewController2 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | |
switch segue.destination { | |
case let viewController1 as ViewController1: | |
self.viewController1 = viewController1 | |
case let viewController2 as ViewController2: | |
self.viewController2 = viewController2 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fileprivate let ref = FIRDatabase.database().reference().child("List_of_stuff") | |
_ = ref.queryLimited(toLast: 30).observe(.value, with: { snapshot in | |
// Do stuff here with the returned elements | |
//... | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ref.queryOrderedByKey().queryEnding(atValue: "last_fetched_element_key").queryLimited(toLast: limit).observeSingleEvent(of: .value, with: { snapshot in | |
// Do stuff with this page of elements | |
//... | |
}) |
OlderNewer