Skip to content

Instantly share code, notes, and snippets.

@andytlr
Last active July 16, 2018 07:35
Show Gist options
  • Select an option

  • Save andytlr/9bb208cb7d36b8914180 to your computer and use it in GitHub Desktop.

Select an option

Save andytlr/9bb208cb7d36b8914180 to your computer and use it in GitHub Desktop.

Revisions

  1. andytlr revised this gist Feb 9, 2016. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions snippets.md
    Original file line number Diff line number Diff line change
    @@ -78,6 +78,14 @@ let scrollTo = CGPointMake(0.0, 57.0)
    scrollView.setContentOffset(scrollTo, animated: true)
    ```

    ## Perform a Segue

    Name your segue by clicking on the line that connects the views in your story board. Go to the Attribues Inspector and give your segue an Indetifier, e.g. `SegueName`.

    ```swift
    performSegueWithIdentifier("SegueName", sender: self)
    ```

    ## Pass a variable on Segue

    In the view controller that you want to receive the variable, set an empty variable and give it a type.
  2. andytlr revised this gist Nov 23, 2015. 1 changed file with 31 additions and 0 deletions.
    31 changes: 31 additions & 0 deletions snippets.md
    Original file line number Diff line number Diff line change
    @@ -133,3 +133,34 @@ if sender.state == .Ended {
    // Runs once when the gesture ends
    }
    ```


    ## Send and Listen for Notifications

    Where you want to send the notification:

    ```swift
    NSNotificationCenter.defaultCenter().postNotificationName("Finished Saving To Camera Roll", object: nil)
    ```

    If you're sending from a non-view file, you might need to wrap it in this to make sure it's on the main thread:

    ```swift
    dispatch_async(dispatch_get_main_queue()) {
    //
    }
    ```

    Then add an 'observer'/listener in the view you want to know about the notification (probably in viewDidLoad):

    ```swift
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "runWhenFinishedSavingToCameraRoll", name: "Finished Saving To Camera Roll", object: nil)
    ```

    Then run the function with that selector at the class level:

    ```swift
    unc runWhenFinishedSavingToCameraRoll() {
    // Tell user it finished saving
    }
    ```
  3. andytlr revised this gist Nov 23, 2015. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions snippets.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,16 @@
    # Swift Snippets

    ## Set light status bar
    ## Change Status Bar

    In the plist file, set `View controller-based status bar appearance` to `NO`. Then in viewDidLoad():
    To make it light, put this inside the View Controller class:

    ```swift
    UIApplication.sharedApplication().statusBarStyle = .LightContent
    override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return .LightContent
    }
    ```

    ## Hide Status bar
    Or to hide it completely:

    ```swift
    override func prefersStatusBarHidden() -> Bool {
  4. andytlr renamed this gist Nov 14, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. andytlr revised this gist Nov 14, 2015. 1 changed file with 12 additions and 4 deletions.
    16 changes: 12 additions & 4 deletions snippets.md
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,14 @@ In the plist file, set `View controller-based status bar appearance` to `NO`. Th
    UIApplication.sharedApplication().statusBarStyle = .LightContent
    ```

    ## Hide Status bar

    ```swift
    override func prefersStatusBarHidden() -> Bool {
    return true
    }
    ```

    ## Make a scroll view with a big image scroll

    Tell the scrollView to be the same size as the imageView:
    @@ -80,10 +88,10 @@ In Source View Controller:

    ```swift
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    // Set the destination view controller name at the end of this line.
    let destinationVC = segue.destinationViewController as! DestinationViewControllerClassName
    // Give it a value at the end of this line.
    destinationVC.emptyVariableInDestinationViewController = thingIWantToSetItTo
    // Set the destination view controller name at the end of this line.
    let destinationVC = segue.destinationViewController as! DestinationViewControllerClassName
    // Give it a value at the end of this line.
    destinationVC.emptyVariableInDestinationViewController = thingIWantToSetItTo
    }
    ```

  6. andytlr revised this gist Nov 14, 2015. 1 changed file with 0 additions and 89 deletions.
    89 changes: 0 additions & 89 deletions snippets.swift
    Original file line number Diff line number Diff line change
    @@ -1,89 +0,0 @@
    // Set light status bar
    ////////////////////////////////////////////////////////////////////////////////
    // In the plist file, set `View controller-based status bar appearance` to `NO`
    // Then in viewDidLoad()
    UIApplication.sharedApplication().statusBarStyle = .LightContent


    // Make a scroll view with a big image scroll
    ////////////////////////////////////////////////////////////////////////////////
    // Tell the scrollView to be the same size as the imageView.
    scrollView.contentSize = imageView.frame.size
    // Or, set it to a pixel size.
    scrollView.contentSize = CGSize(width:375, height:1857)


    // Control a child view controller from a parent.
    ////////////////////////////////////////////////////////////////////////////////
    // Define the first `[0]` of the child view controllers with the class name
    // ChildViewControllerClassName as a variable childVC.
    // Won't always need the `self.`
    let childVC = self.childViewControllers[0] as! ChildViewControllerClassName
    // put `childVC.` before the var you want to control from the child VC.
    childVC.thingToControl.alpha = 1


    // Go Back in Code
    ////////////////////////////////////////////////////////////////////////////////
    // Dismiss a modal
    dismissViewControllerAnimated(true, completion: nil)
    // Go back in the history stack.
    navigationController!.popViewControllerAnimated(true)


    // Do stuff when going back to a view
    ////////////////////////////////////////////////////////////////////////////////
    // viewDidLoad() only runs the first time a view loads. If you push the pop a
    // view and want to run some code try viewDidAppear() or viewWillAppear()
    override func viewDidAppear(animated: Bool) {
    }


    // Set scroll position
    ////////////////////////////////////////////////////////////////////////////////
    let scrollTo = CGPointMake(0.0, 57.0)
    scrollView.setContentOffset(scrollTo, animated: true)
    // In viewDidLoad() to hide a search bar or something like that.


    // Pass a variable on Segue
    ////////////////////////////////////////////////////////////////////////////////
    // In the view controller that I want to receive the variable,
    // set an empty variable and give it a type.
    var emptyVariableInDestinationViewController: Bool!
    // In Source View Controller
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    // Set the destination view controller name at the end of this line.
    let destinationVC = segue.destinationViewController as! DestinationViewControllerClassName
    // Give it a value at the end of this line.
    destinationVC.emptyVariableInDestinationViewController = thingIWantToSetItTo
    }


    // Autolayout getting f-d up?
    ////////////////////////////////////////////////////////////////////////////////
    self.automaticallyAdjustsScrollViewInsets = false
    // in view did load


    // Get scroll position
    ////////////////////////////////////////////////////////////////////////////////
    // See this commit: https://github.com/andytlr/dropbox-carousel/commit/be0ed5dcdc50491995c9e4e1d43e7e21e4ae7dfa


    // Gesture recognizer stuff
    ////////////////////////////////////////////////////////////////////////////////
    // Most common properties in a gesture. These are CGPoints, add .x or .y for axis.
    let location = sender.locationInView(view)
    let translation = sender.translationInView(view)
    let velocity = sender.velocityInView(view)
    // States (go inside the gesture recognizer method)
    if sender.state == .Began {
    // Runs once on start of gesture
    }
    if sender.state == .Changed {
    // Runs constantly as the gesture changes
    }
    if sender.state == .Ended {
    // Runs once when the gesture ends
    }
  7. andytlr revised this gist Nov 14, 2015. 1 changed file with 116 additions and 0 deletions.
    116 changes: 116 additions & 0 deletions snippets.md
    Original file line number Diff line number Diff line change
    @@ -7,3 +7,119 @@ In the plist file, set `View controller-based status bar appearance` to `NO`. Th
    ```swift
    UIApplication.sharedApplication().statusBarStyle = .LightContent
    ```

    ## Make a scroll view with a big image scroll

    Tell the scrollView to be the same size as the imageView:

    ```swift
    scrollView.contentSize = imageView.frame.size
    ```

    Or, set it to a pixel size:

    ```swift
    scrollView.contentSize = CGSize(width:375, height:1857)
    ```

    ## Control a child view controller from a parent.

    Define the first `[0]` of the child view controllers with the class name `ChildViewControllerClassName` as a variable childVC:

    ```swift
    let childVC = self.childViewControllers[0] as! ChildViewControllerClassName
    ```

    Put `childVC.` before the var you want to control from the child VC:

    ```swift
    childVC.thingToControl.alpha = 1
    ```


    ## Go Back in Code

    Dismiss a modal:

    ```swift
    dismissViewControllerAnimated(true, completion: nil)
    ```

    Go back in the history stack:

    ```swift
    navigationController!.popViewControllerAnimated(true)
    ```

    ## Do stuff when going back to a view

    `viewDidLoad()` only runs the first time a view loads. If you want to do something when you pop a view try `viewDidAppear()` or `viewWillAppear()`.

    ```swift
    override func viewDidAppear(animated: Bool) {
    }
    ```


    ## Set scroll position

    ```swift
    let scrollTo = CGPointMake(0.0, 57.0)
    scrollView.setContentOffset(scrollTo, animated: true)
    ```

    ## Pass a variable on Segue

    In the view controller that you want to receive the variable, set an empty variable and give it a type.

    ```swift
    var emptyVariableInDestinationViewController: Bool!
    ```

    In Source View Controller:

    ```swift
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    // Set the destination view controller name at the end of this line.
    let destinationVC = segue.destinationViewController as! DestinationViewControllerClassName
    // Give it a value at the end of this line.
    destinationVC.emptyVariableInDestinationViewController = thingIWantToSetItTo
    }
    ```

    ## Autolayout getting f-d up?

    In `viewDidLoad()`:

    ```swift
    self.automaticallyAdjustsScrollViewInsets = false
    ```

    ## Get scroll position

    See [this commit](https://github.com/andytlr/dropbox-carousel/commit/be0ed5dcdc50491995c9e4e1d43e7e21e4ae7dfa).


    ## Gesture recognizer stuff

    Most common properties in a gesture. These are `CGPoints`, add `.x` or `.y` for axis:

    ```swift
    let location = sender.locationInView(view)
    let translation = sender.translationInView(view)
    let velocity = sender.velocityInView(view)
    ```

    These states go inside the gesture recognizer method:

    ```swift
    if sender.state == .Began {
    // Runs once on start of gesture
    }
    if sender.state == .Changed {
    // Runs constantly as the gesture changes
    }
    if sender.state == .Ended {
    // Runs once when the gesture ends
    }
    ```
  8. andytlr revised this gist Nov 14, 2015. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions snippets.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    # Swift Snippets

    ## Set light status bar

    In the plist file, set `View controller-based status bar appearance` to `NO`. Then in viewDidLoad():

    ```swift
    UIApplication.sharedApplication().statusBarStyle = .LightContent
    ```
  9. andytlr revised this gist Nov 14, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion editingshortcuts.md
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ Xcode has something called "Edit All in Scope" (`ctrl` + `cmd` + `e`). It's simi

    There aren't actually commands for Delete Line and Duplicate Line, but you can edit a plist file to chain multiple actions together into one command. After editing the `.plist` you can add a shortcuts in `Settings` > `Keybindings`.

    Path: `/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist`
    Open `/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist` and put this before the closing `</dict>` and `</plist>` tags:

    ```xml
    <key>Custom</key>
  10. andytlr revised this gist Nov 14, 2015. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions editingshortcuts.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Make Xcode Editing More Like Atom/Sublime

    Go to `Settings` > `Keybindings` to remap or add keyboard shortcuts. When removing existing keybindings, don't press the keyboard Delete key, click the `` icon.
    Go to `Settings` > `Keybindings` to remap or add keyboard shortcuts. When removing existing keybindings, don't press the keyboard Delete key, click the `` icon. Some keybindings can't be deleted `¯\_(ツ)_/¯`; remap these to keybindings that are available.

    ## Multiple Selection

    @@ -26,8 +26,6 @@ Path: `/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/ID
    </dict>
    ```

    Detailed [instructions here](http://stackoverflow.com/questions/5834096/how-do-i-create-a-delete-line-keyboard-shortcut-in-xcode-6-the-xcode-3-solution).

    ## Move Line

    There are commands for Move Line Up and Move Line Down (`cmd` + `option` + `[`/`]`).
  11. andytlr revised this gist Nov 14, 2015. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions editingshortcuts.md
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,16 @@
    ## Make Xcode Editing More Like Atom/Sublime
    # Make Xcode Editing More Like Atom/Sublime

    Go to `Settings` > `Keybindings` to remap or add keyboard shortcuts. When removing existing keybindings, don't press the keyboard Delete key, click the `` icon.

    ### Multiple Selection
    ## Multiple Selection

    Xcode has something called "Edit All in Scope" (`ctrl` + `cmd` + `e`). It's similar but just selects all instances of the selected text.

    ### Open Quickly
    ## Open Quickly

    `command` + `shift` + `o`

    ### Delete Line & Duplicate Line
    ## Delete Line & Duplicate Line

    There aren't actually commands for Delete Line and Duplicate Line, but you can edit a plist file to chain multiple actions together into one command. After editing the `.plist` you can add a shortcuts in `Settings` > `Keybindings`.

    @@ -28,10 +28,10 @@ Path: `/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/ID

    Detailed [instructions here](http://stackoverflow.com/questions/5834096/how-do-i-create-a-delete-line-keyboard-shortcut-in-xcode-6-the-xcode-3-solution).

    ### Move Line
    ## Move Line

    There are commands for Move Line Up and Move Line Down (`cmd` + `option` + `[`/`]`).

    ### More shortcuts
    ## More shortcuts

    This [NSHipster Article](http://nshipster.com/xcode-key-bindings-and-gestures/) covers a lot of other shortcuts.
  12. andytlr revised this gist Nov 14, 2015. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions editingshortcuts.md
    Original file line number Diff line number Diff line change
    @@ -31,3 +31,7 @@ Detailed [instructions here](http://stackoverflow.com/questions/5834096/how-do-i
    ### Move Line

    There are commands for Move Line Up and Move Line Down (`cmd` + `option` + `[`/`]`).

    ### More shortcuts

    This [NSHipster Article](http://nshipster.com/xcode-key-bindings-and-gestures/) covers a lot of other shortcuts.
  13. andytlr revised this gist Nov 14, 2015. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions editingshortcuts.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,18 @@
    ## Make Xcode Editing More Like Atom/Sublime

    Go to `Settings` > `Keybindings` to remap or add keyboard shortcuts.
    Go to `Settings` > `Keybindings` to remap or add keyboard shortcuts. When removing existing keybindings, don't press the keyboard Delete key, click the `` icon.

    ### Multiple Selection

    Xcode has something called "Edit All in Scope" (`ctrl` + `cmd` + `e`). It's similar but just selects all instances of the selected text.

    ### Delete Line
    ### Open Quickly

    There isn't actually a Delete Line command but you can edit a plist file to chain three actions together into one command. Edit the plist, then you can add a shortcut in `Settings` > `Keybindings`.
    `command` + `shift` + `o`

    ### Delete Line & Duplicate Line

    There aren't actually commands for Delete Line and Duplicate Line, but you can edit a plist file to chain multiple actions together into one command. After editing the `.plist` you can add a shortcuts in `Settings` > `Keybindings`.

    Path: `/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist`

    @@ -17,6 +21,8 @@ Path: `/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/ID
    <dict>
    <key>Delete Line</key>
    <string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteToEndOfParagraph:</string>
    <key>Duplicate Line</key>
    <string>moveToBeginningOfLine:, deleteToEndOfLine:, yank:, insertNewline:, moveToBeginningOfLine:, yank:</string>
    </dict>
    ```

  14. andytlr revised this gist Nov 14, 2015. 1 changed file with 27 additions and 0 deletions.
    27 changes: 27 additions & 0 deletions editingshortcuts.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    ## Make Xcode Editing More Like Atom/Sublime

    Go to `Settings` > `Keybindings` to remap or add keyboard shortcuts.

    ### Multiple Selection

    Xcode has something called "Edit All in Scope" (`ctrl` + `cmd` + `e`). It's similar but just selects all instances of the selected text.

    ### Delete Line

    There isn't actually a Delete Line command but you can edit a plist file to chain three actions together into one command. Edit the plist, then you can add a shortcut in `Settings` > `Keybindings`.

    Path: `/Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Resources/IDETextKeyBindingSet.plist`

    ```xml
    <key>Custom</key>
    <dict>
    <key>Delete Line</key>
    <string>moveToEndOfLine:, deleteToBeginningOfLine:, deleteToEndOfParagraph:</string>
    </dict>
    ```

    Detailed [instructions here](http://stackoverflow.com/questions/5834096/how-do-i-create-a-delete-line-keyboard-shortcut-in-xcode-6-the-xcode-3-solution).

    ### Move Line

    There are commands for Move Line Up and Move Line Down (`cmd` + `option` + `[`/`]`).
  15. andytlr revised this gist Nov 5, 2015. 1 changed file with 23 additions and 0 deletions.
    23 changes: 23 additions & 0 deletions snippets.swift
    Original file line number Diff line number Diff line change
    @@ -64,3 +64,26 @@ override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    ////////////////////////////////////////////////////////////////////////////////
    self.automaticallyAdjustsScrollViewInsets = false
    // in view did load


    // Get scroll position
    ////////////////////////////////////////////////////////////////////////////////
    // See this commit: https://github.com/andytlr/dropbox-carousel/commit/be0ed5dcdc50491995c9e4e1d43e7e21e4ae7dfa


    // Gesture recognizer stuff
    ////////////////////////////////////////////////////////////////////////////////
    // Most common properties in a gesture. These are CGPoints, add .x or .y for axis.
    let location = sender.locationInView(view)
    let translation = sender.translationInView(view)
    let velocity = sender.velocityInView(view)
    // States (go inside the gesture recognizer method)
    if sender.state == .Began {
    // Runs once on start of gesture
    }
    if sender.state == .Changed {
    // Runs constantly as the gesture changes
    }
    if sender.state == .Ended {
    // Runs once when the gesture ends
    }
  16. andytlr revised this gist Oct 27, 2015. 1 changed file with 9 additions and 1 deletion.
    10 changes: 9 additions & 1 deletion snippets.swift
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    UIApplication.sharedApplication().statusBarStyle = .LightContent


    // Set a scroll view to the height of an image view
    // Make a scroll view with a big image scroll
    ////////////////////////////////////////////////////////////////////////////////
    // Tell the scrollView to be the same size as the imageView.
    scrollView.contentSize = imageView.frame.size
    @@ -31,6 +31,14 @@ dismissViewControllerAnimated(true, completion: nil)
    navigationController!.popViewControllerAnimated(true)


    // Do stuff when going back to a view
    ////////////////////////////////////////////////////////////////////////////////
    // viewDidLoad() only runs the first time a view loads. If you push the pop a
    // view and want to run some code try viewDidAppear() or viewWillAppear()
    override func viewDidAppear(animated: Bool) {
    }


    // Set scroll position
    ////////////////////////////////////////////////////////////////////////////////
    let scrollTo = CGPointMake(0.0, 57.0)
  17. andytlr revised this gist Oct 27, 2015. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions snippets.swift
    Original file line number Diff line number Diff line change
    @@ -50,3 +50,9 @@ override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    // Give it a value at the end of this line.
    destinationVC.emptyVariableInDestinationViewController = thingIWantToSetItTo
    }


    // Autolayout getting f-d up?
    ////////////////////////////////////////////////////////////////////////////////
    self.automaticallyAdjustsScrollViewInsets = false
    // in view did load
  18. andytlr revised this gist Oct 27, 2015. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions snippets.swift
    Original file line number Diff line number Diff line change
    @@ -36,3 +36,17 @@ navigationController!.popViewControllerAnimated(true)
    let scrollTo = CGPointMake(0.0, 57.0)
    scrollView.setContentOffset(scrollTo, animated: true)
    // In viewDidLoad() to hide a search bar or something like that.


    // Pass a variable on Segue
    ////////////////////////////////////////////////////////////////////////////////
    // In the view controller that I want to receive the variable,
    // set an empty variable and give it a type.
    var emptyVariableInDestinationViewController: Bool!
    // In Source View Controller
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    // Set the destination view controller name at the end of this line.
    let destinationVC = segue.destinationViewController as! DestinationViewControllerClassName
    // Give it a value at the end of this line.
    destinationVC.emptyVariableInDestinationViewController = thingIWantToSetItTo
    }
  19. andytlr revised this gist Oct 26, 2015. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions snippets.swift
    Original file line number Diff line number Diff line change
    @@ -29,3 +29,10 @@ childVC.thingToControl.alpha = 1
    dismissViewControllerAnimated(true, completion: nil)
    // Go back in the history stack.
    navigationController!.popViewControllerAnimated(true)


    // Set scroll position
    ////////////////////////////////////////////////////////////////////////////////
    let scrollTo = CGPointMake(0.0, 57.0)
    scrollView.setContentOffset(scrollTo, animated: true)
    // In viewDidLoad() to hide a search bar or something like that.
  20. andytlr revised this gist Oct 26, 2015. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions snippets.swift
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,15 @@
    // Set light status bar
    ////////////////////////////////////////////////////////////////////////////////
    UIApplication.sharedApplication().statusBarStyle = .LightContent
    // In the plist file, set `View controller-based status bar appearance` to `NO`
    // Then in viewDidLoad()
    UIApplication.sharedApplication().statusBarStyle = .LightContent


    // Set a scroll view to the height of an image view
    ////////////////////////////////////////////////////////////////////////////////
    // Tell the scrollView to be the same size as the imageView.
    scrollView.contentSize = imageView.frame.size
    // Or set it to a pixel size
    // Or, set it to a pixel size.
    scrollView.contentSize = CGSize(width:375, height:1857)


  21. andytlr revised this gist Oct 26, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions snippets.swift
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@
    UIApplication.sharedApplication().statusBarStyle = .LightContent
    // In the plist file, set `View controller-based status bar appearance` to `NO`


    // Set a scroll view to the height of an image view
    ////////////////////////////////////////////////////////////////////////////////
    scrollView.contentSize = imageView.frame.size
    @@ -19,6 +20,7 @@ let childVC = self.childViewControllers[0] as! ChildViewControllerClassName
    // put `childVC.` before the var you want to control from the child VC.
    childVC.thingToControl.alpha = 1


    // Go Back in Code
    ////////////////////////////////////////////////////////////////////////////////
    // Dismiss a modal
  22. andytlr revised this gist Oct 26, 2015. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions snippets.swift
    Original file line number Diff line number Diff line change
    @@ -18,3 +18,10 @@ scrollView.contentSize = CGSize(width:375, height:1857)
    let childVC = self.childViewControllers[0] as! ChildViewControllerClassName
    // put `childVC.` before the var you want to control from the child VC.
    childVC.thingToControl.alpha = 1

    // Go Back in Code
    ////////////////////////////////////////////////////////////////////////////////
    // Dismiss a modal
    dismissViewControllerAnimated(true, completion: nil)
    // Go back in the history stack.
    navigationController!.popViewControllerAnimated(true)
  23. andytlr revised this gist Oct 24, 2015. 1 changed file with 7 additions and 6 deletions.
    13 changes: 7 additions & 6 deletions snippets.swift
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,20 @@
    // Set light status bar
    /////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    UIApplication.sharedApplication().statusBarStyle = .LightContent
    // In the plist file, set `View controller-based status bar appearance` to `NO`

    // Set a scroll view to the height of an image view
    /////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    scrollView.contentSize = imageView.frame.size
    // Or set it to a pixel size
    scrollView.contentSize = CGSize(width:375, height:1857)


    // Control a child view controller from a parent.
    /////////////////////////////////////////////////////////////////////////////////////
    // Define the first `[0]` of the child view controllers with the class name ChildViewControllerClassName as a variable childVC
    ////////////////////////////////////////////////////////////////////////////////
    // Define the first `[0]` of the child view controllers with the class name
    // ChildViewControllerClassName as a variable childVC.
    // Won't always need the `self.`
    let childVC = self.childViewControllers[0] as! ChildViewControllerClassName
    // put `childVC.` before the var you want to control from the child view controller.
    childVC.thingToControl.alpha = 1
    // put `childVC.` before the var you want to control from the child VC.
    childVC.thingToControl.alpha = 1
  24. andytlr revised this gist Oct 24, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions snippets.swift
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,17 @@
    // Set light status bar
    //
    /////////////////////////////////////////////////////////////////////////////////////
    UIApplication.sharedApplication().statusBarStyle = .LightContent
    // In the plist file, set `View controller-based status bar appearance` to `NO`

    // Set a scroll view to the height of an image view
    //
    /////////////////////////////////////////////////////////////////////////////////////
    scrollView.contentSize = imageView.frame.size
    // Or set it to a pixel size
    scrollView.contentSize = CGSize(width:375, height:1857)


    // Control a child view controller from a parent.
    //
    /////////////////////////////////////////////////////////////////////////////////////
    // Define the first `[0]` of the child view controllers with the class name ChildViewControllerClassName as a variable childVC
    // Won't always need the `self.`
    let childVC = self.childViewControllers[0] as! ChildViewControllerClassName
  25. andytlr revised this gist Oct 24, 2015. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions snippets.swift
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,8 @@
    // Set light status bar
    //
    UIApplication.sharedApplication().statusBarStyle = .LightContent
    // In the plist file, set `View controller-based status bar appearance` to `NO`

    // Set a scroll view to the height of an image view
    //
    scrollView.contentSize = imageView.frame.size
  26. andytlr revised this gist Oct 24, 2015. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion snippets.swift
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,12 @@
    // Control a child view controller from a parent.
    // Set a scroll view to the height of an image view
    //
    scrollView.contentSize = imageView.frame.size
    // Or set it to a pixel size
    scrollView.contentSize = CGSize(width:375, height:1857)


    // Control a child view controller from a parent.
    //
    // Define the first `[0]` of the child view controllers with the class name ChildViewControllerClassName as a variable childVC
    // Won't always need the `self.`
    let childVC = self.childViewControllers[0] as! ChildViewControllerClassName
  27. andytlr created this gist Oct 24, 2015.
    7 changes: 7 additions & 0 deletions snippets.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    // Control a child view controller from a parent.

    // Define the first `[0]` of the child view controllers with the class name ChildViewControllerClassName as a variable childVC
    // Won't always need the `self.`
    let childVC = self.childViewControllers[0] as! ChildViewControllerClassName
    // put `childVC.` before the var you want to control from the child view controller.
    childVC.thingToControl.alpha = 1