This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func applicationDidEnterBackground(application: UIApplication) { | |
// Create a pseudo background task to system call applicationWillTerminate when app enter background | |
// Default system will not call applicationWillTerminate when app enter background | |
// applicationWillTerminate only called when user close app in app switcher or some special cases of system | |
bgTask = application.beginBackgroundTaskWithExpirationHandler({ () -> Void in | |
application.endBackgroundTask(self.bgTask) | |
self.bgTask = UIBackgroundTaskInvalid | |
}) | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { () -> Void in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RKlcl_configure_by_name("RestKit/Network", RKlcl_vTrace.rawValue) | |
RKlcl_configure_by_name("RestKit/ObjectMapping", RKlcl_vDebug.rawValue) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RadioBox: UIButton { | |
var borderColor: UIColor = UIColor.lightGrayColor() | |
var innerColor: UIColor = UIColor.linkTextColor() | |
var borderWidthPercent: Int = 40 { | |
didSet { | |
borderWidthPercent = max(min(borderWidthPercent, 90), 10) | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 { | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
OlderNewer