A demo that shows five ways to pass data between ViewControllers, including Segues in Storyboard, Delegate Pattern, Passing Blocks, Key-value Observation and NSNotification. Source Code
Besides showing the data passing mechanism, other functions includes:
  • Use PaintCode to draw the icons in the TabBar and UIView
  • Explore PaintCode’s frame function and  scale the icons to different sizes
  • Generate image using template mode and dynamically change the image / icon color
  • Extended UIColor so it can be initiated with UIColor(color: UIColor, alpha: CGFloat)
  • Explore TabBar and UITabBarController, including custom icon, system icon, badge, and “More” icon
  • Keep consistent UIView in different orientation
snapshot
snapshot0
snapshot
Takeaways:
  • use viewDidLayoutSubviews to redraw the UIView
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
iconView.frame = view.bounds
iconView.setNeedsDisplay()
}
  • Use image.tintColor to redraw image with different UIColor
  • Use UIApplication.sharedApplication().keyWindow?.tintColor to set global TintColor
  • Use CGColorGetComponents(color.CGColor) to get the corresponding RGB value of the CGColor
  • Use SegmentedControl’s valueChanged event to trigger Action