Created
April 18, 2015 13:14
-
-
Save martinnormark/f67f8ceea07c15f3ebc9 to your computer and use it in GitHub Desktop.
Swift enum to return ready-to-use UIImageView with a logo from asset library.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
enum LogoView : UIViewConvertible { | |
case Default() | |
case Large() | |
case Symbol() | |
// MARK: UIViewConvertible | |
var View: UIView { | |
switch self { | |
case .Large(): | |
return UIImageView(image: UIImage(named: "logo-large")?.imageWithRenderingMode(.AlwaysTemplate)) | |
case .Symbol(): | |
return UIImageView(image: UIImage(named: "logo-symbol")?.imageWithRenderingMode(.AlwaysTemplate)) | |
default: | |
return UIImageView(image: UIImage(named: "logo-default")?.imageWithRenderingMode(.AlwaysTemplate)) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
public protocol UIViewConvertible { | |
var View: UIView { get } | |
} | |
extension UIView: UIViewConvertible { | |
public var View: UIView { | |
return self | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment