Skip to content

Instantly share code, notes, and snippets.

View y8k's full-sized avatar
🤟
For peace!

YoonBong Kim y8k

🤟
For peace!
View GitHub Profile
@y8k
y8k / gist:55927b714678f66842d3
Last active August 29, 2015 14:19
Howto: Get UIImage from UIColor
func imageFromColor(color:UIColor) -> UIImage {
let rect = CGRectMake(0.0, 0.0, 1.0, 1.0)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext() as CGContextRef
CGContextSetFillColorWithColor(context, color.CGColor)
CGContextFillRect(context, rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
@y8k
y8k / gist:e4efba584cbd6318752b
Created April 22, 2015 16:44
Howto: If you want to attach image to end of text
let title = String("It's latest news! ")
var attributedString = NSMutableAttributedString(string: title)
let attachment = NSTextAttachment()
attachment.image = UIImage(named: "NoticeNewIcon")
let attachmentAttributedString = NSAttributedString(attachment: attachment)
attributedString.appendAttributedString(attachmentAttributedString)
@y8k
y8k / gist:3c84c91ea74053632539
Last active August 29, 2015 14:19
Howto: Set top space to match vertical align attached image with text
class TDTextAttachment: NSTextAttachment {
var topSpace: Float = 0.0
convenience init(image: UIImage, topSpace: Float = 0.0) {
self.init()
self.image = image
self.topSpace = 0.0
}
@y8k
y8k / UTTextField.swift
Created September 1, 2015 13:58
Customized UITextField
//
// UTTextField.swift
// YFGAddressBook
//
// Created by KimYoonBong on 2015. 8. 28..
// Copyright © 2015년 YMP. All rights reserved.
//
import UIKit
@y8k
y8k / UITextField delegate
Created September 1, 2015 14:05
UITextField delegate
func textFieldDidBeginEditing(textField: UITextField) {
self.showMessageToUser(nil)
}
func textFieldDidEndEditing(textField: UITextField) {
if textField.text?.characters.count <= 0 {
if let hasLabel = textField as? UTTextField {
hasLabel.changeStatus(.Normal)
}
@y8k
y8k / gist:d9489ed2dccd42950220
Created October 22, 2015 05:53
NSSearchDirectory example with enum of PicturesDirectory
let paths = NSSearchPathForDirectoriesInDomains(.PicturesDirectory, .UserDomainMask, true)
let path = paths[0]
if !NSFileManager.defaultManager().fileExistsAtPath(path) {
print("have to create directory...")
do {
try NSFileManager.defaultManager().createDirectoryAtPath(path, withIntermediateDirectories: true, attributes: nil)
}
catch let error as NSError {
print(error)
@y8k
y8k / gist:d84d5bb614c949b82782
Created October 26, 2015 05:11
AppDelegate methods for Home screen quick actions
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
self.handleShortCutItem(shortcutItem)
}
func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) {
guard let rootViewCntrlr = self.window?.rootViewController else {
return
}
@y8k
y8k / gist:c96c6811b9d72c0b31a3
Created October 26, 2015 05:21
Dynamic quick actions example
let firstShortCutIcon = UIApplicationShortcutIcon(templateImageName: "ShortCut01")
let firstFunctionShortCutItem = UIApplicationShortcutItem(type: "com.y8k.touchExample.function01", localizedTitle: "Member Func. 1", localizedSubtitle: "Dynamic short cut item", icon: firstShortCutIcon, userInfo: nil)
let secondShortCutIcon = UIApplicationShortcutIcon(templateImageName: "ShortCut02")
let secondFunctionShortCutItem = UIApplicationShortcutItem(type: "com.y8k.touchExample.function02", localizedTitle: "Member Func. 2", localizedSubtitle: "Dynamic short cut item", icon: secondShortCutIcon, userInfo: nil)
UIApplication.sharedApplication().shortcutItems = [firstFunctionShortCutItem, secondFunctionShortCutItem]
@y8k
y8k / gist:dd108513388f3188211c
Last active October 27, 2015 02:54
Register for 3D touch previewing.
class PresentedViewController: UITableViewController, UIViewControllerPreviewingDelegate {
...
override func viewDidLoad() {
super.viewDidLoad()
registerForPreviewingWithDelegate(self, sourceView: view)
}
@y8k
y8k / gist:9e203413b10f16e9bd5b
Created October 27, 2015 05:06
Implementation Peek for 3D Touch
func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
guard let indexPath = self.tableView.indexPathForRowAtPoint(location), cell = self.tableView.cellForRowAtIndexPath(indexPath) else { return nil }
let selectedData = self.data[indexPath.row]
var detailViewCntrlr: UIViewController?
switch selectedData.type {
case .List:
detailViewCntrlr = self.storyboard?.instantiateViewControllerWithIdentifier("DETAIL_LIST_SCREEN")