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
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) | |
} |
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
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") | |
} |
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
// 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) |
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 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!) |