This file contains hidden or 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
<!-- Use WP Query to get some posts for the home page --> | |
<div id='' class=""> | |
<?php | |
// Get an archive of categories with category_name=slug where slug is the slug name for the category | |
// Add another option to the query following the & | |
// Use post_per_page=# to set the number of most recent posts to display | |
$art_post = new WP_Query( "category_name=your-category-name-here&posts_per_page=3" ); | |
if ( $art_post->have_posts() ) : while ( $art_post->have_posts() ) : | |
$art_post->the_post(); | |
?> |
This file contains hidden or 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
// Simple drag using pan UIPanGestureRecognizer | |
func handlePanGesture(panGesture: UIPanGestureRecognizer) { | |
// translation | |
let translation = panGesture.translationInView(view) | |
panGesture.setTranslation(CGPointZero, inView: view) | |
// DX DY | |
let object = panGesture.view as! UIView | |
var offset = object.center | |
object.center = CGPoint(x: object.center.x + translation.x, y: object.center.y + translation.y) | |
} |
This file contains hidden or 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
// UNTESTED! | |
extension UIView { | |
func takeScreenshot() -> UIImage { | |
UIGraphicsBeginImageContextWithOptions(self.bounds.size, true, 0.0) | |
self.drawViewHierarchyInRect(self.bounds, afterScreenUpdates: true) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return image | |
} |
This file contains hidden or 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 completeRowAtIndexPath(indexPath: NSIndexPath) { | |
print("Completing row: \(indexPath.row)") | |
let cell = tableView.cellForRowAtIndexPath(indexPath) | |
let todo = array[indexPath.row] | |
todo.completed = !todo.completed | |
if todo.completed { | |
// cell?.accessoryType = .Checkmark | |
let ribbon = UIImage(named: "Ribbon") | |
cell?.accessoryView = UIImageView(image: ribbon) | |
} else { |
This file contains hidden or 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
// http://apps.timwhitlock.info/emoji/tables/unicode | |
let delete = UITableViewRowAction(style: .Destructive, title: "\u{267A}\n Delete") { (action: UITableViewRowAction, indexPath: NSIndexPath) -> Void in | |
self.deleteRowAtIndexPath(indexPath) | |
tableView.editing = false | |
} | |
delete.backgroundColor = UIColor.redColor() |
This file contains hidden or 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, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { | |
let complete = UITableViewRowAction(style: .Normal, title: "Complete") { (action: UITableViewRowAction, indexPath: NSIndexPath) -> Void in | |
self.completeRowAtIndexPath(indexPath) | |
} | |
complete.backgroundColor = UIColor.greenColor() | |
let delete = UITableViewRowAction(style: .Destructive, title: "Delete") { (action: UITableViewRowAction, indexPath: NSIndexPath) -> Void in | |
self.deleteRowAtIndexPath(indexPath) | |
} | |
delete.backgroundColor = UIColor.redColor() |
This file contains hidden or 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
// Currency style | |
let formatter = NSNumberFormatter() | |
formatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle | |
let costString = formatter.stringFromNumber(23.99) | |
// Round to nearest whole number | |
let wholeNumberformatter = NSNumberFormatter() | |
let wholeNumber = wholeNumberformatter.stringFromNumber(3.145) | |
// Round to nearest whole number |
This file contains hidden or 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 formatter = NSNumberFormatter() | |
formatter.numberStyle = NSNumberFormatterStyle.CurrencyStyle | |
let costString = formatter.stringFromNumber(cost) |
This file contains hidden or 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
import UIKit | |
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { | |
// Must be declared here! | |
var picker = UIImagePickerController() | |
// IBOutlets | |
This file contains hidden or 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
enum TagColor { | |
case Red, Orange, Yellow, Green, Blue, Purple | |
func toUIColor() -> UIColor { | |
switch self { | |
case .Red: | |
return UIColor(red: 179, green: 47, blue: 60, alpha: 1) | |
case .Orange: | |
return UIColor(red: 248, green: 148, blue: 29, alpha: 1) | |
case .Yellow: |