//
//  FuelGaugeView.swift
//  FuelGaugeKit
//
//  Created by Ron Lisle on 3/19/15.
//  Copyright (c) 2015 Ron Lisle. All rights reserved.
//

import UIKit

class FuelGaugeView: UIView {

    var backgroundImage:UIImageView!
    var needleImage:UIImageView!

    override func layoutSubviews() {
        super.layoutSubviews()
        
        if backgroundImage == nil {
            backgroundImage = createSubviewWithImageNamed("FuelGaugeBG")
        }
        if needleImage == nil {
            needleImage = createSubviewWithImageNamed("FuelGaugeNeedle")
        }
    }
    
    func createSubviewWithImageNamed(name: String) -> UIImageView {
        let newImageView = createImageViewWithImageNamed(name)
        addSubview(newImageView)
        return newImageView
    }
    
    func createImageViewWithImageNamed(name: String) -> UIImageView {
        let newImageView = UIImageView()
        newImageView.frame = self.bounds
        newImageView.image = loadImageNamed(name)
        return newImageView
    }
    
    func loadImageNamed(name: String) -> UIImage? {
        let newImage = UIImage(named: name, inBundle: NSBundle(forClass: FuelGaugeView.self), compatibleWithTraitCollection: nil)
        return newImage
    }
}

//
//  FuelGaugeView.swift
//  FuelGaugeKit
//
//  Created by Ron Lisle on 3/19/15.
//  Copyright (c) 2015 Ron Lisle. All rights reserved.
//

import UIKit

class FuelGaugeView: UIView {

    var backgroundImage:UIImageView!
    var needleImage:UIImageView!

    override func layoutSubviews() {
        super.layoutSubviews()
        
        if backgroundImage == nil {
            backgroundImage = createSubviewWithImageNamed("FuelGaugeBG")
        }
        if needleImage == nil {
            needleImage = createSubviewWithImageNamed("FuelGaugeNeedle")
        }
    }
    
    func createSubviewWithImageNamed(name: String) -> UIImageView {
        let newImageView = createImageViewWithImageNamed(name)
        addSubview(newImageView)
        return newImageView
    }
    
    func createImageViewWithImageNamed(name: String) -> UIImageView {
        let newImageView = UIImageView()
        newImageView.frame = self.bounds
        newImageView.image = UIImage(named: name, inBundle: NSBundle(forClass: FuelGaugeView.self), compatibleWithTraitCollection: nil)
        return newImageView
    }
}

--- 
+++ 
@@ -33,7 +33,12 @@
     func createImageViewWithImageNamed(name: String) -> UIImageView {
         let newImageView = UIImageView()
         newImageView.frame = self.bounds
-        newImageView.image = UIImage(named: name, inBundle: NSBundle(forClass: FuelGaugeView.self), compatibleWithTraitCollection: nil)
+        newImageView.image = loadImageNamed(name)
         return newImageView
     }
+    
+    func loadImageNamed(name: String) -> UIImage? {
+        let newImage = UIImage(named: name, inBundle: NSBundle(forClass: FuelGaugeView.self), compatibleWithTraitCollection: nil)
+        return newImage
+    }
 }
Refactor to loadImageNamed. 8 tests still passing.
