added iOS source code
[wl-app.git] / iOS / WolneLektury / Extensions / UIImage+Ext.swift
diff --git a/iOS/WolneLektury/Extensions/UIImage+Ext.swift b/iOS/WolneLektury/Extensions/UIImage+Ext.swift
new file mode 100644 (file)
index 0000000..b339384
--- /dev/null
@@ -0,0 +1,27 @@
+//
+//  UIImage+Ext.swift
+//  WolneLektury
+//
+//  Created by Pawel Dabrowski on 30/05/2018.
+//  Copyright © 2018 Fundacja Nowoczesna Polska. All rights reserved.
+//
+
+import Foundation
+import UIKit
+
+extension UIImage{
+    
+    static func imageFromColor(colour: UIColor) -> UIImage? {
+        let rect = CGRect(x: 0, y: 0, width: 1, height: 1)
+        UIGraphicsBeginImageContext(rect.size)
+        if let context = UIGraphicsGetCurrentContext() {
+            context.setFillColor(colour.cgColor)
+            context.fill(rect)
+            
+            let image = UIGraphicsGetImageFromCurrentImageContext()
+            UIGraphicsEndImageContext()
+            return image
+        }
+        return nil
+    }
+}