Skip to content

Instantly share code, notes, and snippets.

View quangtqag's full-sized avatar
🚀
Researching things that I am lacking...

Quang quangtqag

🚀
Researching things that I am lacking...
View GitHub Profile
@quangtqag
quangtqag / AppDelegate.swift
Created December 10, 2015 02:56
Log RestKit
RKlcl_configure_by_name("RestKit/Network", RKlcl_vTrace.rawValue)
RKlcl_configure_by_name("RestKit/ObjectMapping", RKlcl_vDebug.rawValue)
class RadioBox: UIButton {
var borderColor: UIColor = UIColor.lightGrayColor()
var innerColor: UIColor = UIColor.linkTextColor()
var borderWidthPercent: Int = 40 {
didSet {
borderWidthPercent = max(min(borderWidthPercent, 90), 10)
}
}
import UIKit
class CheckBox: UIButton {
let roundedRectStrokeColor = UIColor.GBTint()
let roundedRectFillColor = UIColor.whiteColor()
let checkmarkColor = UIColor.greenColor()
override func drawRect(rect: CGRect) {
super.drawRect(rect)
extension UIColor {
class func mainTextColor() -> UIColor { return UIColor(hex: 0x000000) }
class func subTextColor() -> UIColor { return UIColor(hex: 0x656565) }
}
extension UIColor {
convenience init(red: Int, green: Int, blue: Int) {
assert(red >= 0 && red <= 255, "Invalid red component")
@quangtqag
quangtqag / PushTextfieldUp.swift
Last active January 19, 2016 04:16
Push text field up to prevent keyboard cover in table view
override func viewWillAppear(animated: Bool) {
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
}
override func viewWillDisappear(animated: Bool) {
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillShowNotification, object: nil)
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil)
}
@quangtqag
quangtqag / StringExt.swift
Last active April 29, 2016 08:56
Get height of text block with given width and font
extension String {
func heightWithConstrainedWidth(width: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: width, height: CGFloat.max)
let boundingBox = self.boundingRectWithSize(constraintRect, options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil)
return boundingBox.height
}
func isEmail() -> Bool {
func convertVideoToMP4WithInputURL(inputURL: NSURL, outputURL: NSURL, callback: (error: NSError?) -> ()) {
let asset = AVURLAsset(URL: inputURL)
let exportSession = AVAssetExportSession(asset: asset, presetName: AVAssetExportPresetPassthrough)!
exportSession.outputURL = outputURL
exportSession.outputFileType = AVFileTypeMPEG4
exportSession.exportAsynchronouslyWithCompletionHandler {
callback(error: exportSession.error)
}
}
// Custom animation for pull to refresh function as of GMail app
// View figure https://blog.xamarin.com/wp-content/uploads/2013/06/device-swipe-down-refresh.png
// Use combine with https://github.com/jcavar/refresher
import Foundation
import Refresher
import QuartzCore
class BeatAnimator: UIView, PullToRefreshViewDelegate {
let image = UIImage(named: "images.jpeg")!
UIGraphicsBeginImageContextWithOptions(image.size, false, 1.0)
var context = UIGraphicsGetCurrentContext()
//move and invert canvas by scaling
CGContextTranslateCTM(context, image.size.width, 0)
CGContextScaleCTM(context, -1, 1)
image.drawInRect(CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height))
let image = UIImage(named: "images.jpeg")!
let degrees: Double = 90
let rads = CGFloat(M_PI * degrees / 180)
UIGraphicsBeginImageContext(CGSizeMake(image.size.height, image.size.width))
let ctx = UIGraphicsGetCurrentContext()
CGContextTranslateCTM(ctx, image.size.height/2, image.size.width/2)
CGContextRotateCTM(ctx, rads)
CGContextScaleCTM(ctx, 1.0, -1.0)