Skip to content

Instantly share code, notes, and snippets.

View aataraxiaa's full-sized avatar
:octocat:
Focusing

Pete Smith aataraxiaa

:octocat:
Focusing
  • DuckDuckGo
  • 05:41 (UTC)
View GitHub Profile
@aataraxiaa
aataraxiaa / UIImageWithText
Created November 17, 2015 20:41
Swift function for adding text to a UIImage
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,
@aataraxiaa
aataraxiaa / LocationTodayExtension.swift
Created March 24, 2016 07:56
How to create a location-based iOS Today Extension using Swift
//
// TodayViewController.swift
// LocationTodayExtension
//
// Created by Pete Smith on 24/03/2016.
// Copyright © 2016 Pete Smith. All rights reserved.
//
import UIKit
import NotificationCenter
//: Playground - noun: a place where people can play
import UIKit
enum State {
case initial
case launched
case launchingWithLocation
case launchingWithoutLocation
case running
@aataraxiaa
aataraxiaa / rot13_Swift3.txt
Created December 15, 2016 10:59
rot13 in Swift 3
// 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]
@aataraxiaa
aataraxiaa / UITextView+NewHeight.swift
Last active September 22, 2023 16:35
UITextView extension with method to calculate new height based on content
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 {
@aataraxiaa
aataraxiaa / ScalingCarouselView_CenterCell.swift
Created March 5, 2017 11:23
Method of calculating the centre cell in ScalingCarousel
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
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
}
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
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
//...
})
ref.queryOrderedByKey().queryEnding(atValue: "last_fetched_element_key").queryLimited(toLast: limit).observeSingleEvent(of: .value, with: { snapshot in
// Do stuff with this page of elements
//...
})