Skip to content

Instantly share code, notes, and snippets.

View nvkiet's full-sized avatar

Kiet Nguyen - CoFounder & CEO at GrabLingo.com nvkiet

View GitHub Profile
@nvkiet
nvkiet / [Swift] Switch-RootViewController
Last active June 21, 2023 12:35
Switch root view controller
func switchRootViewController(rootViewController: UIViewController, animated: Bool, completion: (() -> Void)?) {
if animated {
UIView.transitionWithView(window, duration: 0.5, options: .TransitionCrossDissolve, animations: {
let oldState: Bool = UIView.areAnimationsEnabled()
UIView.setAnimationsEnabled(false)
self.window!.rootViewController = rootViewController
UIView.setAnimationsEnabled(oldState)
}, completion: { (finished: Bool) -> () in
if completion {
completion!()
@nvkiet
nvkiet / [Swift]KeepUItableviewStatic
Created August 17, 2014 06:12
Keep uitableview static when inserting rows at the top
private func addListBubbleCellsWithCount(count: Int) {
var contentOffset = self.tableView.contentOffset
UIView.setAnimationsEnabled(false)
var indexPaths = [NSIndexPath]()
var heightForNewRows: CGFloat = 0
for var i = 0; i < count; i++ {
let indexPath = NSIndexPath(forRow: i, inSection: 0)
@nvkiet
nvkiet / gist:29e4d5b5bef0865ee159
Created September 24, 2015 07:53
UIAlertController TextAlignment
if #available(iOS 8.0, *) {
let alertController = UIAlertController(title: "Terms & Conditions", message: kTermsAndConditions, preferredStyle: .Alert)
let OKAction = UIAlertAction(title: "OK", style: .Cancel) { (action) in
alertController.dismissViewControllerAnimated(true, completion: nil)
}
alertController.addAction(OKAction)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.Left
@nvkiet
nvkiet / [Swift] Hide-show keyboard
Created August 20, 2014 14:16
Hide/Show keyboard with Swift language
func handleKeyboardWillShowNotification(notification: NSNotification) {
if self.inputContainerViewBottomLayoutGuideConstraint.constant == 0 {
keyboardWillChangeFrameWithNotification(notification, showKeyboard: true)
scrollBubbleTableViewToBottomAnimated(true)
}
}
func handleKeyboardWillHideNotification(notification: NSNotification) {
if self.inputContainerViewBottomLayoutGuideConstraint.constant > 0 {
keyboardWillChangeFrameWithNotification(notification, showKeyboard: false)

#Users Resources

GET users/me

##Description Get my User object


Parameters

@nvkiet
nvkiet / [Swift] GetCountryNames
Last active April 23, 2016 20:36
Declare a static variable in a function
class func countryNames() -> [String] {
struct Static {
static var instance: [String]?
}
if let names = Static.instance {
return names
}
var names = [String]()
for code in NSLocale.ISOCountryCodes() as [String] {
@nvkiet
nvkiet / UIImagePickerController.markdown
Last active November 11, 2015 05:54
UIImagePickerController
+ (UIImagePickerController *)tp_getCameraPickeWithParentViewController:(id<UINavigationControllerDelegate, UIImagePickerControllerDelegate, TPOverlayCameraViewDelegate>)parentViewController {
    
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
        imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePickerController.delegate = parentViewController;
        imagePickerController.showsCameraControls = NO;
        
@nvkiet
nvkiet / UIViewAnimation.markdown
Last active October 25, 2015 16:21
UIView Animation
[UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:10.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
        self.view.superview.top -= FilterViewHeight;
    } completion:^(BOOL finished) {
        self.isShown = YES;
        if ([self.delegate respondsToSelector:@selector(filterViewControllerDidShow:)]) {
            [self.delegate filterViewControllerDidShow:self];
        }
 }];
@nvkiet
nvkiet / createPDFfromUIView
Created May 18, 2015 07:50
createPDFfromUIView
- (void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
{
// Creates a mutable data object for updating with binary data, like a byte array
NSMutableData *pdfData = [NSMutableData data];
// Points the pdf converter to the mutable data object and to the UIView to be converted
UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();