Skip to content

Instantly share code, notes, and snippets.

View phucnm's full-sized avatar
😬
eager to learn

Tony Nguyen phucnm

😬
eager to learn
  • Vancouver, BC, Canada
View GitHub Profile
@phucnm
phucnm / gist:6c3d324e95973d2d831eb0153582fa99
Created December 6, 2016 03:49
Shortest way to extract all images frame of a video using ffmpeg
Run this command:
```ffmpeg -i input.mp4 out%d.png```
If you want more options, check this ref: https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video
@phucnm
phucnm / RoundCornerProgressView.swift
Last active November 29, 2016 08:55
iOS IBDesignable Progress View with flexible height and corner radius on any corners.
//
// RoundCornerProgressView.swift
// PhucNguyen
//
// Created by Phuc Nguyen on 8/18/16.
// Copyright © 2016 Phuc Nguyen. All rights reserved.
//
import UIKit
@phucnm
phucnm / gist:5074b03b6cc75fde9bb07a1a4fb99d08
Created August 30, 2016 03:04
HTML String to Attribute String in Swift 2.1
import Foundation
import UIKit
extension String {
var html2AttributedString: NSAttributedString? {
guard
let data = dataUsingEncoding(NSUTF8StringEncoding)
else { return nil }
do {
@phucnm
phucnm / gist:c0de1422917695dff4d079a746d6f4a3
Last active August 30, 2016 03:17
Reorder Table View
// Created by Phuc Nguyen on 7/15/16.
// Copyright © 2016 Phuc Nguyen. All rights reserved.
//
import Foundation
class ReorderTableView: UITableView {
var isReorderEnabled = true
var customView:UIImageView?
@phucnm
phucnm / gist:ab866adf2538b4b2c2b252c6d6e92498
Last active July 8, 2016 04:14
Makes the whole table view cell draggable and reorderable in Swift
//Implement your willDisplayCell delegate function like that
//Behind the scene
//It will hide default reorder control image (three horizontal lines)
//but the table view cell can still receive drag action to reorder rows
//You still need to set `tableView.editing = true`
//and `tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool` to return `true`
//Finally, implement `tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath)`
//to handle your data changes
@phucnm
phucnm / gist:79fc6c29cb6d30f357340cc1718c1b27
Created June 7, 2016 03:47
UIImage with gradient color
extension UIImage {
/**
Create gradient image from beginColor on top and end color at bottom
- parameter beginColor: beginColor
- parameter endColor: endColor
- parameter frame: frame to be filled
- returns: filled image
*/
@phucnm
phucnm / gist:84ad5179428f15cfd53daf7e6b0cc71f
Created June 7, 2016 03:46
Makes navigation bar transparent alpha = 0
/**
Snippet to make navigation bar transparent alpha = 0
*/
func makesNavigationBarTransparent() {
navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
navigationController?.navigationBar.shadowImage = UIImage()
navigationController?.navigationBar.translucent = true
navigationController?.navigationBar.backgroundColor = UIColor.clearColor()
}
@phucnm
phucnm / gist:4bb915bcfe7933e211e234b49728f299
Created May 30, 2016 07:33
Present a viewcontroller with transparent background
self.definesPresentationContext = YES;
presentedController.view.backgroundColor = [YOUR_COLOR with alpha OR clearColor]
presentedController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:presentedController animated:YES completion:nil];
@phucnm
phucnm / gist:77a4ba13f30efff0c475b2c7e56c2d1a
Created April 14, 2016 08:14
Detect current page number in paging enabled Collection view
// Scrollview.tag will equal to your collection view's tag
// Use page to update page control or whatever
func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
print("tag = \(scrollView.tag)")
let pageWidth = scrollView.frame.size.width
let page = Int(floor((scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1)
print("page = \(page)")
}
@phucnm
phucnm / gist:5dbc2ede166ed55503032000c158b6b0
Last active April 14, 2016 05:37
How to update section header in UI Table View ?
Store section header in an array and change their value :)
Ooops, I think dictionary is better hehe