Skip to content

Instantly share code, notes, and snippets.

let todoEndpoint: String = "https://api.instagram.com/oauth/authorize/?client_id=0cf37b02d4404a58addf08b680bc20e2&redirect_uri=https://www.terrybu.com&response_type=code"
guard let url = NSURL(string: todoEndpoint) else {
print("Error: cannot create URL")
return
}
let urlRequest = NSURLRequest(url: url as URL)
// set up the session
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config)
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func loadView() {
let view = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 375.0, height: 667.0))
view.backgroundColor = .white
let circle = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 50.0, height: 50.0))
@terrybu
terrybu / floating middle button tab bar
Created December 9, 2015 20:37
original way to get floating middle button to work for tab bar
let buttonImage = UIImage(named: "Btn_Menu_BROWSE_INACTIVE_03")
let button = UIButton(type: UIButtonType.Custom)
button.autoresizingMask = [UIViewAutoresizing.FlexibleRightMargin, .FlexibleLeftMargin, .FlexibleBottomMargin, .FlexibleTopMargin]
button.frame = CGRectMake(0.0, 0.0, buttonImage!.size.width, buttonImage!.size.height);
let buttonHighlighted = UIImage(named: "Btn_Menu_BROWSE_ACTIVE_03")
button.setBackgroundImage(buttonImage, forState: UIControlState.Normal)
button.setBackgroundImage(buttonHighlighted, forState: UIControlState.Highlighted)
let heightDifference = buttonImage!.size.height - self.tabBar.frame.size.height;
if (heightDifference < 0) {
button.center = self.tabBar.center
@terrybu
terrybu / autolayout in code in swift
Created November 16, 2015 18:18
autolayout in code in swift
self.canvasView!.addSubview(label)
let widthConstraint = NSLayoutConstraint(item: label, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.LessThanOrEqual, toItem: self.view, attribute: NSLayoutAttribute.Width, multiplier: 1, constant: -40)
self.view.addConstraint(widthConstraint)
class TasteMatchesView: UIView {
var view: UIView!
override init(frame: CGRect) {
super.init(frame: frame)
setUp()
}
required init?(coder aDecoder: NSCoder) {
@terrybu
terrybu / gist:45cc7e04f32eae36e29f
Created November 4, 2015 22:13
registering a uitableviewcell with identifier (when using XIBs instead of storyboard) in the viewdidload of your viewcontroller with tableview in it
tableView.registerNib(UINib(nibName: "CommunicationsTableViewCell", bundle: nil), forCellReuseIdentifier: "CommunicationsCell")
let emailImgView = UIImageView(image: UIImage(named: "btn_close"))
let paddedEmailImgView = UIView(frame: CGRect(x: 0, y: 0, width: 40, height: 32))
paddedEmailImgView.addSubview(emailImgView)
emailField.leftViewMode = UITextFieldViewMode.Always
emailField.leftView = paddedEmailImgView
@terrybu
terrybu / fonts.swift
Last active December 25, 2015 21:58
Checking what fonts are available on your iOS project currently
var myArray = UIFont.familyNames() as Array
print(myArray)
print(UIFont.fontNamesForFamilyName("NanumBarunGothic"))
@terrybu
terrybu / forLoop.swift
Created August 2, 2015 13:57
For loop swift
for var i = 1; i <= 10; i++ {
println(i)
}
@terrybu
terrybu / completion.swift
Created August 1, 2015 18:39
swift completion handlers
//Create a Completion Handler
func isTextValid(input: String, completion: (result: Bool) -> Void) {
if (input == "Vea Software") {
completion(result: true)
} else {
completion(result: false)
}
})
//Call a Completion Handler