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 / sample.py
Created December 26, 2016 05:29 — forked from kgriffs/sample.py
Falcon Web Framework (http://falconframework.org)
# sample.py
import falcon
import json
class QuoteResource:
def on_get(self, req, resp):
"""Handles GET requests"""
quote = {
'quote': 'I\'ve always been more interested in the future than in the past.',
'author': 'Grace Hopper'
/// Generated Alamofire Router
import Alamofire
import Foundation
public typealias JSONDictionary = [String: AnyObject]
public typealias Username = String
public typealias ObjectId = String
public typealias Email = String
@JaleelNazir
JaleelNazir / 7.swift
Created October 27, 2016 05:55
Pure Visual Format Language style
override func viewDidLoad() {
super.viewDidLoad()
let newView = UIView()
newView.backgroundColor = UIColor.redColor()
newView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(newView)
let views = ["view": view, "newView": newView]
let horizontalConstraints = NSLayoutConstraint.constraintsWithVisualFormat("H:[view]-(<=0)-[newView(100)]", options: NSLayoutFormatOptions.AlignAllCenterY, metrics: nil, views: views)
@JaleelNazir
JaleelNazir / 6.swift
Created October 27, 2016 05:53
Subclassing style
import UIKit
class CustomView: UIView {
override var intrinsicContentSize: CGSize {
return CGSize(width: 100, height: 100)
}
}
class ViewController: UIViewController {
@JaleelNazir
JaleelNazir / 5.swift
Created October 27, 2016 05:52
5. `NSLayoutAnchor` style
override func viewDidLoad() {
super.viewDidLoad()
let newView = UIView()
newView.backgroundColor = UIColor.red
newView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(newView)
let horizontalConstraint = newView.centerXAnchor.constraint(equalTo: view.centerXAnchor)
let verticalConstraint = newView.centerYAnchor.constraint(equalTo: view.centerYAnchor)
@JaleelNazir
JaleelNazir / 4.swift
Created October 27, 2016 05:50
4. `UIViewAutoresizing` style
override func viewDidLoad() {
super.viewDidLoad()
let newView = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
newView.backgroundColor = UIColor.red
newView.translatesAutoresizingMaskIntoConstraints = true
view.addSubview(newView)
newView.center = CGPoint(x: view.bounds.midX, y: view.bounds.midY)
newView.autoresizingMask = [UIViewAutoresizing.flexibleLeftMargin, UIViewAutoresizing.flexibleRightMargin, UIViewAutoresizing.flexibleTopMargin, UIViewAutoresizing.flexibleBottomMargin]
@JaleelNazir
JaleelNazir / 3.swift
Created October 27, 2016 05:45
3. `NSLayoutConstraint` + Visual Format Language 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)
@JaleelNazir
JaleelNazir / 2.swift
Created October 27, 2016 05:42
2. `NSLayoutConstraint` + `activate(_ 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)
@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)