Skip to content

Instantly share code, notes, and snippets.

View JaleelNazir's full-sized avatar
🚣‍♀️
Focusing

Jaleel Nazir JaleelNazir

🚣‍♀️
Focusing
View GitHub Profile
@JaleelNazir
JaleelNazir / UILabelSubClass
Created February 25, 2016 11:41 — forked from saiday/UILabelSubClass
Self calculate height label
- (void)layoutSubviews
{
[super layoutSubviews];
if (self.numberOfLines == 0 && self.preferredMaxLayoutWidth != CGRectGetWidth(self.frame)) {
self.preferredMaxLayoutWidth = self.frame.size.width;
[self setNeedsUpdateConstraints];
}
}
@JaleelNazir
JaleelNazir / contentsOfDirectoryAtPath.swift
Created May 27, 2016 14:08 — forked from kristopherjohnson/contentsOfDirectoryAtPath.swift
Using NSFileManager contentsOfDirectoryAtPath in Swift, with tuple result and CPS interfaces
import Foundation
// Tuple result
// Get contents of directory at specified path, returning (filenames, nil) or (nil, error)
func contentsOfDirectoryAtPath(path: String) -> (filenames: String[]?, error: NSError?) {
var error: NSError? = nil
let fileManager = NSFileManager.defaultManager()
let contents = fileManager.contentsOfDirectoryAtPath(path, error: &error)
@JaleelNazir
JaleelNazir / ask.swift
Created September 30, 2016 07:28
ask() - Show an OK/Cancel modal box that works in both iOS 7 and iOS 8
/// Show an OK/Cancel modal box that works in both iOS 7 and iOS 8
func ask(title: String, #message: String, #completion: (answer: Bool) -> Void) {
if nil != objc_getClass("UIAlertController".UTF8String) { // use UIAlertController
let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: { (action) -> Void in
completion(answer: false)
})
let okayAction = UIAlertAction(title: "OK", style: .Default, handler: { (action) -> Void in
completion(answer: true)
})
@JaleelNazir
JaleelNazir / MovieWriter.swift
Created October 14, 2016 09:33 — forked from isthisjoe/MovieWriter.swift
Swift 3 | macOs | Write NSImage(s) to a movie file. Modified from http://stackoverflow.com/a/36297656/1275125
import AppKit
import AVFoundation
class MovieWriter: NSObject {
func writeImagesAsMovie(_ allImages: [NSImage], videoPath: String, videoSize: CGSize, videoFPS: Int32) {
// Create AVAssetWriter to write video
guard let assetWriter = createAssetWriter(videoPath, size: videoSize) else {
print("Error converting images to video: AVAssetWriter not created")
return
}
@JaleelNazir
JaleelNazir / BuildTimeLapseViewController.swift
Created October 15, 2016 09:56 — forked from acj/ATTENTION.md
Build a movie from jpeg images in Swift using AVFoundation
//
// BuildTimelapseViewController.swift
//
// Created by Adam Jensen on 5/9/15.
//
import JGProgressHUD
import JoePro
import UIKit
<?
/*
This is part of the Reprise framework, not yet released publicly.
Copyright 2013 Marco Arment. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
import Foundation
extension String
{
var length: Int {
get {
return countElements(self)
}
}
//
// ColorUtil.swift
// FantasyMovieLeague
//
// Created by Ben Dalziel on 2/17/16.
// Copyright © 2016 Kinetoplay. All rights reserved.
//
import SwiftHEXColors
//
// FontUtil.swift
// FantasyMovieLeague
//
// Created by Ben Dalziel on 2/17/16.
// Copyright © 2016 Kinetoplay. All rights reserved.
//
import UIKit
@JaleelNazir
JaleelNazir / 1.swift
Created October 27, 2016 05:40
`NSLayoutConstraint` + `addConstraints(_ constraints: [NSLayoutConstraint])` style
override func viewDidLoad() {
super.viewDidLoad()
let newView = UIView()
newView.backgroundColor = UIColor.red
newView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(newView)
let horizontalConstraint = NSLayoutConstraint(item: newView, attribute: NSLayoutAttribute.centerX, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.centerX, multiplier: 1, constant: 0)
let verticalConstraint = NSLayoutConstraint(item: newView, attribute: NSLayoutAttribute.centerY, relatedBy: NSLayoutRelation.equal, toItem: view, attribute: NSLayoutAttribute.centerY, multiplier: 1, constant: 0)