O'Reilly logo

Xcode 7 Essentials - Second Edition by Jayant Varma, Brett Ohland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Advanced drawing with CALayer

Our first example was very simple; we simply recreated functionality that was already present in a default view. Creating a much more complicated Custom Control is possible by drawing lines, images, or text into view using CALayer. This is a part of the QuartzCore Cocoa framework designed to efficiently draw on the screen using code.

We're going to draw a box on our view and expose several properties so that they can be modified from within IB:

import UIKit @IBDesignable class CustomControlView: UIView { @IBInspectable var layerBackgroundColor:UIColor = UIColor.lightGrayColor() @IBInspectable var layerStrokeColor:UIColor = UIColor.lightGrayColor() @IBInspectable var layerStrokeWidth:CGFloat = 2 override func layoutSubviews() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required