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
// | |
// Reference: https://www.raywenderlich.com/79150/grand-central-dispatch-tutorial-swift-part-2 | |
// | |
var GlobalMainQueue: dispatch_queue_t { | |
return dispatch_get_main_queue() | |
} | |
var GlobalUserInteractiveQueue: dispatch_queue_t { | |
return dispatch_get_global_queue(Int(QOS_CLASS_USER_INTERACTIVE.value), 0) |
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
// | |
// Reference from http://samwize.com/2015/11/06/guide-to-customizing-uitableview-section-header-footer/ | |
// | |
class TableSectionHeader: UITableViewHeaderFooterView { | |
@IBOutlet weak var titleLabel: UILabel! | |
} | |
let nib = UINib(nibName: "TableSectionHeader", bundle: nil) | |
tableView.registerNib(nib, forHeaderFooterViewReuseIdentifier: "TableSectionHeader") |
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 tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { | |
cell.separatorInset = UIEdgeInsetsZero | |
cell.preservesSuperviewLayoutMargins = false | |
cell.layoutMargins = UIEdgeInsetsMake(0, 8, 0, 0) | |
} |
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 MyView: UIView { | |
@IBOutlet weak var label: UILabel! | |
class func instanceFromNib() -> MyView { | |
return UINib(nibName: "MyView", bundle: nil).instantiateWithOwner(nil, options: nil)[0] as! MyView | |
} | |
} |
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 getSearchTextField() -> UITextField { | |
return valueForKey("_searchField") as! UITextField | |
} |
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 UIView { | |
func allConstraints() -> [NSLayoutConstraint] { | |
var constraints = [NSLayoutConstraint]() | |
constraints += self.constraints | |
var superview = self.superview | |
while superview != nil { | |
for c in superview!.constraints { | |
if c.firstItem as? UIView == self || c.secondItem as? UIView == self { | |
constraints.append(c) |
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
NSLayoutConstraint.activateConstraints(constraints) | |
UIView.animateWithDuration(0.5) { | |
self.view.layoutIfNeeded() | |
} |
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 fixOrientation() -> UIImage { | |
// No-op if the orientation is already correct | |
if ( self.imageOrientation == UIImageOrientation.Up ) { | |
return self; | |
} | |
// We need to calculate the proper transformation to make the image upright. | |
// We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored. | |
var transform: CGAffineTransform = CGAffineTransformIdentity |
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 asset = AVURLAsset(URL: NSURL(string: self.scheduleCelebrityGame.videoLink!)!, options: nil) | |
let imgGenerator = AVAssetImageGenerator(asset: asset) | |
do { | |
let cgImage = try imgGenerator.copyCGImageAtTime(CMTimeMake(0, 1), actualTime: nil) | |
let uiImage = UIImage(CGImage: cgImage, scale: CGFloat(1.0), orientation: UIImageOrientation.Right) | |
let uiImageJPEG = UIImageJPEGRepresentation(uiImage, 1.0)! | |
} catch { | |
} |