Skip to content

Instantly share code, notes, and snippets.

View katiesmillie's full-sized avatar

Katie Smillie katiesmillie

View GitHub Profile
@katiesmillie
katiesmillie / URLRoute.swift
Last active May 1, 2019 22:07
Parsing a deep link like urbanarchive://posts/9987
// Call from App Delegate
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
guard let components = URLComponents(string: url.absoluteString), let scheme = components.scheme else { return true }
let absolute = url.absoluteString
let path = absolute.replacingOccurrences(of: "\(scheme)://", with: "")
launchCoordinator.appCoordinator.deepLink(path: path)
return true
@katiesmillie
katiesmillie / CustomNavBar.swift
Last active November 10, 2021 21:49
Transition nav bar from translucent to white when scrolling
// Add to View Controller
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
customNavBar?.makeTransparent = true
// Match the style based scroll view position on the page everytime view appears
styleNavBarBasedOnScrollViewPosition(tableView)
}
@katiesmillie
katiesmillie / CircleProgressView.swift
Created February 16, 2017 20:59
Circular Progress View (starts at the 12:00 position like App Store or Netflix downloading indicator)
// Adapated from https://www.raywenderlich.com/94302/implement-circular-image-loader-animation-cashapelayer
// Swift 3
// Init with frame size or set in storyboard and use an IBOutlet
// Set end stroke to 1 and animate with duration, or pass in the progress (between 0 and 1) while downloading, etc
class CircleProgressView: UIView {
let circlePathLayer = CAShapeLayer()
let circleRadius: CGFloat = 10.0
@katiesmillie
katiesmillie / Date+Extension.swift
Created January 27, 2017 15:56
Time Ago String Swift 3
extension: Date {
var timeAgoString: String {
let interval = Calendar.current.dateComponents([.year, .month, .day, .hour], from: self, to: Date())
if let year = interval.year, year > 0 {
return year == 1 ? "\(year) year ago" : "\(year) years ago"
} else if let month = interval.month, month > 0 {
return month == 1 ? "\(month) month ago" : "\(month) months ago"
} else if let day = interval.day, day > 0 {
func imageByAddingBorder(width: CGFloat, color: UIColor) -> UIImage? {
UIGraphicsBeginImageContext(self.size)
let imageRect = CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height)
self.draw(in: imageRect)
let context = UIGraphicsGetCurrentContext()
let borderRect = imageRect.insetBy(dx: width / 2, dy: width / 2)
context?.setStrokeColor(color.cgColor)
@katiesmillie
katiesmillie / gist:833c67cd9be8d1603eed9ae9c071e087
Created December 5, 2016 15:38
UIImage Extension Swift 3 - Change Alpha & Scale / Change Size
extension UIImage {
func alpha(value: CGFloat) -> UIImage {
let format = UIGraphicsImageRendererFormat()
return UIGraphicsImageRenderer(size: size, format: format).image { _ in
draw(at: CGPoint.zero, blendMode: .normal, alpha: value)
}
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
func tappedFacebook(sharingOptionsView: SharingOptionsView) {
Analytics().track(event: "Share Facebook")
guard let imageToShare = makeCompositeToShare() else { return }
let photo = FBSDKSharePhoto()
photo.image = imageToShare
photo.isUserGenerated = true
let content = FBSDKSharePhotoContent()
content.photos = [photo]
FBSDKShareDialog.show(from: self, with: content, delegate: nil)
}
func tappedInstagram(sharingOptionsView: SharingOptionsView) {
Analytics().track(event: "Share Instagram")
guard let instagramURL = URL(string: "instagram://app") else {return}
if UIApplication.shared.canOpenURL(instagramURL) {
guard let imageToShare = makeCompositeToShare() else { return }
let imageData = UIImageJPEGRepresentation(imageToShare, 1.0)
do {
func swiftCracklePop() {
var myArray = [String]()
for i in 1...100 {
if i % 5 == 0 && i % 3 == 0 {
myArray.append("CracklePop")
} else if i % 3 == 0 {
myArray.append("Crackle")