Skip to content

Instantly share code, notes, and snippets.

View UjwalManjunath's full-sized avatar

Ujwal Manjunath UjwalManjunath

View GitHub Profile
@UjwalManjunath
UjwalManjunath / PrintFonts.swift
Created February 5, 2016 17:00
Print all fonts: IOS - Swift 2.1
func printFonts() {
let fontFamilyNames = UIFont.familyNames()
for familyName in fontFamilyNames {
print("------------------------------")
print("Font Family Name = [\(familyName)]")
let names = UIFont.fontNamesForFamilyName(familyName)
print("Font Names = [\(names)]")
}
}
@UjwalManjunath
UjwalManjunath / UIColor+HexString.swift
Created February 5, 2016 17:18
creates a UIColor from a hex string
extension UIColor {
class func HTSDColorWithHexString (hex:String) -> UIColor {
var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).uppercaseString
if (cString.hasPrefix("#")) {
cString = (cString as NSString).substringFromIndex(1)
}
if (cString.characters.count != 6) {
public extension UITableView {
func registerClass(myClass:AnyClass) {
let bundle = NSBundle(forClass: myClass)
self.registerNib(UINib(nibName: String(myClass), bundle: bundle), forCellReuseIdentifier: String(myClass))
}
func dequeue<T where T:UITableViewCell>(myclass:T.Type) -> T {
return self.dequeueReusableCellWithIdentifier(String(myclass)) as! T
}
import Foundation
import UIKit
extension UIView {
func constraintForAttribute(attribute:NSLayoutAttribute) -> NSLayoutConstraint? {
for constraint in self.constraints {
if constraint.firstAttribute == attribute {
return constraint
}