Skip to content

Instantly share code, notes, and snippets.

View jazzedge's full-sized avatar

Rocco Labellarte jazzedge

View GitHub Profile
01. Begin by declaring that the View Controller class implements the
UIImagePickerControllerDelegate and UINavigationControllerDelegate protocols,
then within the ViewController.swift file implement the code as follows:
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
.
.
@IBAction func selectPhoto(_ sender: AnyObject) {
let imagePicker = UIImagePickerController()
@jazzedge
jazzedge / Swift - Hide keyboard when user touches screen
Last active December 9, 2017 10:59
It is important to include code to ensure that the user has a way to hide the keyboard after entering text into the two text areas in the user interface. Within the ViewController.swift file, override the touchesBegan method to hide the keyboard when the user taps the background view of the user interface:
// See: https://stackoverflow.com/questions/32281651/how-to-dismiss-keyboard-when-touching-anywhere-outside-uitextfield-in-swift
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}
// For specific fields you can try:
override func touchesBegan(_ touches: Set<UITouch>,
with event: UIEvent?) {
See: https://www.appcoda.com/cloudkit-introduction-tutorial/
01. Declare:
var imageURL: NSURL!
let documentsDirectoryPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! NSString
let tempImageName = "temp_image.jpg"
02. Create a custom method
Source: BorgGreen
func drawLine(xorig: CGFloat, yorig: Int, xlen: Int, ylen: Int, color: CGColor) {
let doYourPath = UIBezierPath(rect: CGRect(x: Int(xorig), y: yorig, width: xlen, height: ylen))
let layer = CAShapeLayer()
layer.path = doYourPath.cgPath
layer.strokeColor = color
layer.fillColor = color
Source: Yippidoo
01. Include the Extension Class RoundButton.swift
import UIKit
@IBDesignable
class RoundButton: UIButton {
@IBInspectable var cornerRadius: CGFloat = 0 {
@jazzedge
jazzedge / Swift - AppDelegate
Last active November 29, 2017 17:37
How to set statusBarStyle and UINavigationBar for all VCs
//See: https://stackoverflow.com/questions/43073623/changing-the-color-of-the-status-bar
Source: BorgGreen
01. First in Plist set View controller-based status bar appearance to NO
02. Add this code to AppDelegate.swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Set Status Bar to light colour for ALL ViewControllers
See: http://purelywebdesign.co.uk/tutorial/swift-underlined-text-field-tutorial/
Source: BorgGreen
01. EXTENSION
import UIKit
extension UITextField {
func underlined(){
let border = CALayer()
@jazzedge
jazzedge / Swift - Class Extension of UIViewController
Last active November 29, 2017 17:37
You can extend with a class, the default UIViewController to set values for all VCs in your app.
Source: BorgGreen
01. Create a new class...
import UIKit
class BaseViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
@jazzedge
jazzedge / Swift - Extension to create a curved edge UIView
Last active November 29, 2017 20:29
This extension allows you to call one of two functions and set one or more corners of a UIView to curve. If you set, for example, the bottomLeft and bottomRight corners, your UIView will have an outward curved base.
See: https://stackoverflow.com/questions/31232689/how-to-set-cornerradius-for-only-bottom-left-bottom-right-and-top-left-corner-te/41217791#41217791
Source: CurvedView
EXTENSION:
import UIKit
extension UIView {
func roundCorners(_ corners:UIRectCorner, radius: CGFloat) {
@jazzedge
jazzedge / Swift - Extension to create a round Image with shadow on a UIView
Last active November 29, 2017 20:29
If you have an image which needs to be clippedToBounds, then you can't draw a shadow around it Instead you have to first drop a UIView on your storyboard to act as the background. You add a UIImageView to the UIView you just dropped. Make sure it is constrained to 0,0,0,0 against the underlying background UIView. You set clippedToBounds = true f…
See: https://stackoverflow.com/questions/39624675/add-shadow-on-uiview-using-swift-3
Source:ViewShadow
Here is the extension with two functions of the same name, one with, the other without parameters.
import UIKit
extension UIView {