 
 
 	public var preferredSize: CGSize?
+
+
+	@IBInspectable
+	public var scaling: Scaling = .FitInside {
+		didSet {
+			guard scaling != oldValue else {
+				return
+			}
+
+			if image != nil {
+				setNeedsDisplay()
+			}
+		}
+	}
 
 
 	public override func sizeThatFitsSize(maximumSize: CGSize) -> CGSize {

			if !drawFrame.isEmpty {
				if image.renderingMode == .AlwaysTemplate {
					let viewSize = bounds.size
					
					let context = UIGraphicsGetCurrentContext()
					CGContextSaveGState(context)
					CGContextScaleCTM(context, 1, -1)
					CGContextTranslateCTM(context, 0, -viewSize.height)
					CGContextClipToMask(context, drawFrame, image.CGImage)
					tintColor.setFill()
					CGContextFillRect(context, drawFrame)

			imageSize = image.size

			if !imageSize.isEmpty && !availableFrame.isEmpty {
				switch scaling {
				case .FitIgnoringAspectRatio:
					drawFrame.size = availableFrame.size

				case .FitInside, .FitOutside:
					let horizontalScale = availableFrame.width / imageSize.width
					let verticalScale = availableFrame.height / imageSize.height
					let scale = (scaling == .FitInside ? min : max)(horizontalScale, verticalScale)

					drawFrame.size = imageSize.scaleBy(scale)

				case .FitHorizontally:
					drawFrame.width = availableFrame.width
					drawFrame.height = imageSize.height * (drawFrame.width / imageSize.width)

				case .FitHorizontallyIgnoringAspectRatio:
					drawFrame.width = availableFrame.width
					drawFrame.height = imageSize.height

				case .FitVertically:
					drawFrame.height = availableFrame.height
					drawFrame.width = imageSize.width * (drawFrame.height / imageSize.height)

				case .FitVerticallyIgnoringAspectRatio:
					drawFrame.height = availableFrame.height
					drawFrame.width = imageSize.width

				case .None:
					drawFrame.size = imageSize
				}

				switch gravity.horizontal {
				case .Left:
					drawFrame.left = availableFrame.left

				case .Center:
					drawFrame.horizontalCenter = availableFrame.horizontalCenter

				case .Right:
					drawFrame.right = availableFrame.right
				}

				switch gravity.vertical {
				case .Top:
					drawFrame.top = availableFrame.top

				case .Center:
					drawFrame.verticalCenter = availableFrame.verticalCenter

				case .Bottom:
					drawFrame.bottom = availableFrame.bottom
				}

				drawFrame = roundScaled(drawFrame)
