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.
Swift Snippets
// Set light status bar
////////////////////////////////////////////////////////////////////////////////
// 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.
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)
// 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment