Атрибуты IBInspectable и IBDesignable

Xcode 6 обзавелся новыми атрибутами, позволяющими вживую отображать ваши подклассы UIView через Interface Builder, и там же определять значения свойств. Все, что для этого нужно — пометить класс как @IBDesignable, а свойства как @IBInspectable, поддерживаемые типы: Int, CGFloat, Double, String, Bool, CGPoint, CGSize, CGRect, UIColor, UIImage.

import UIKit

@IBDesignable
class FlagView: UIView {
    @IBInspectable var firstColor: UIColor = UIColor.clearColor() {
        didSet {
           setNeedsDisplay()
        }
    }

    @IBInspectable var secondColor: UIColor = UIColor.clearColor() {
        didSet {
            setNeedsDisplay()
        }
    }

    @IBInspectable var thirdColor: UIColor = UIColor.clearColor() {
        didSet {
            setNeedsDisplay()
        }
    }

    override func drawRect(rect: CGRect) {
        let context = UIGraphicsGetCurrentContext()
        let width = bounds.width
        let height = bounds.height / 3
  
        firstColor.setFill()
        CGContextFillRect(context, CGRect(x: 0, y: 0, width: width, height: height))

        secondColor.setFill()
        CGContextFillRect(context, CGRect(x: 0, y: height, width: width, height: height))

        thirdColor.setFill()
        CGContextFillRect(context, CGRect(x: 0, y: 2 * height, width: width, height: height))
    }
}
Set FlagView class Set custom attributes