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
private func strokeCircle() {
let context = UIGraphicsGetCurrentContext()
let lineWidth: CGFloat = 5
let innerRect: CGRect = CGRectInset(self.bounds, lineWidth/2, lineWidth/2)
let strokeColor: CGColor = UIColor.blueColor().CGColor
CGContextSetStrokeColorWithColor(context, strokeColor)
CGContextSetLineWidth(context, lineWidth)
CGContextStrokeEllipseInRect(context, innerRect)
}
import AVFoundation
private func showDialogWithTitle(title: String?, msg: String?) {
let alertController = UIAlertController(title: title, message: msg, preferredStyle: UIAlertControllerStyle.Alert)
alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alertController, animated: true, completion: nil)
}
@IBAction func didTapButton(sender: AnyObject) {
let authorizationStatus: AVAuthorizationStatus = AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo)
var block: dispatch_block_t?
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(animated: Bool) {
block = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS) {
print("I executed")
}
// iOS 9 or Above
// Reference: https://www.raywenderlich.com/125718/coding-auto-layout
//
avatarView.translatesAutoresizingMaskIntoConstraints = false
avatarView.topAnchor.constraintEqualToAnchor(topLayoutGuide.bottomAnchor).active = true
avatarView.leadingAnchor.constraintEqualToAnchor(view.layoutMarginsGuide.leadingAnchor).active = true
chapterLabel.centerXAnchor.constraintEqualToAnchor(view.centerXAnchor).active = true
avatarView.bottomAnchor.constraintEqualToAnchor(chapterLabel.topAnchor,constant: -10).active = true
chapterLabel.setContentHuggingPriority(UILayoutPriorityRequired, forAxis: .Vertical)
chapterLabel.setContentCompressionResistancePriority(UILayoutPriorityRequired, forAxis: .Vertical)
//
// 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)
//
// 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")
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
cell.separatorInset = UIEdgeInsetsZero
cell.preservesSuperviewLayoutMargins = false
cell.layoutMargins = UIEdgeInsetsMake(0, 8, 0, 0)
}
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
}
}
func getSearchTextField() -> UITextField {
return valueForKey("_searchField") as! UITextField
}
extension UIViewController {
class func currentViewController() -> UIViewController {
let rootViewController = UIApplication.sharedApplication().delegate?.window!?.rootViewController
func findBestViewController(vc: UIViewController) -> UIViewController? {
if let pvc = vc.presentedViewController {
return findBestViewController(pvc)
}
else if let svc = vc as? UISplitViewController where svc.viewControllers.count > 0 {
return findBestViewController(svc.viewControllers.last!)