Skip to content

Instantly share code, notes, and snippets.

import UIKit
@IBDesignable
class DemoView: UIView {
override func awakeFromNib() {
setupViews()
}
@IBInspectable var integer: NSInteger = 10
@IBInspectable var float: CGFloat = 10
@IBInspectable var double: Double = 10
@IBInspectable var string: String = "string"
@IBInspectable var bool: Bool = true
@IBInspectable var point: CGPoint = CGPointMake(1, 0)
@IBInspectable var rect: CGRect = CGRectMake(0, 0, 100, 100)
@IBInspectable var color: UIColor = UIColor.redColor()
@IBInspectable var size: CGSize = CGSizeMake(100, 100)
@IBInspectable var image: UIImage = UIImage(named: "ElectricPeelLogo")!
@justinmstuart
justinmstuart / ViewController.swift
Last active August 29, 2015 14:05
Respond to a User Changing the Text Size in System Preferences
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "preferredContentSizeChanged", name: UIContentSizeCategoryDidChangeNotification, object: nil)
}
func preferredContentSizeChanged () {
NSLog("User wants the Font to Change")
label.font = UIFont.preferredCustomFontForTextStyle(UIFontTextStyleBody)
@justinmstuart
justinmstuart / UIFont+CustomFont.swift
Last active July 20, 2017 03:04
UIFont Extension for Custom Dynamic Font
import UIKit
extension UIFont {
class func preferredCustomFontForTextStyle (textStyle: NSString) -> UIFont {
let fontsDictionary = NSDictionary (contentsOfFile: NSBundle.mainBundle().pathForResource("CustomFontNames", ofType: "plist")!)
let font = UIFontDescriptor.preferredFontDescriptorWithTextStyle(textStyle)
let fontSize: CGFloat = font.pointSize
if textStyle == UIFontTextStyleHeadline || textStyle == UIFontTextStyleSubheadline {
if let boldFontName = (fontsDictionary.valueForKey("Bold Font Name") as String?) {
@justinmstuart
justinmstuart / CustomLabel.swift
Created August 25, 2014 15:18
Custom Label Font Example
customLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)
@justinmstuart
justinmstuart / NSArray+Statistics.m
Last active June 14, 2019 03:36
Calculate Summary Statistics for Array: Sum, Mean, Min, Max, Standard Deviation
#import "NSArray+Statistics.h"
@implementation NSArray (Statistics)
- (NSNumber *)sum {
NSNumber *sum = [self valueForKeyPath:@"@sum.self"];
return sum;
}
- (NSNumber *)mean {