Skip to content

Instantly share code, notes, and snippets.

@martinnormark
Created April 18, 2015 13:14
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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.
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))
}
}
}
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