Skip to content

Instantly share code, notes, and snippets.

@maysamsh
Last active January 18, 2020 21:59
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maysamsh/99eda58ec5f78bc78be99a930299c74c to your computer and use it in GitHub Desktop.
Save maysamsh/99eda58ec5f78bc78be99a930299c74c to your computer and use it in GitHub Desktop.
//
// UIImage+Ext.swift
// frazeit
//
// Created by Maysam Shahsavari on 9/24/19.
// Copyright © 2019 Maysam Shahsavari. All rights reserved.
//
import Foundation
import UIKit
extension UIImage {
func imageWithPixelSize(size: CGSize, filledWithColor color: UIColor = UIColor.clear, opaque: Bool = false) -> UIImage? {
return imageWithSize(size: size, filledWithColor: color, scale: 1.0, opaque: opaque)
}
func imageWithSize(size: CGSize, filledWithColor color: UIColor = UIColor.clear, scale: CGFloat = 0.0, opaque: Bool = false) -> UIImage? {
let rect = CGRect.init(x: 0, y: 0, width: size.width, height: size.height)
UIGraphicsBeginImageContextWithOptions(size, opaque, scale)
color.set()
UIRectFill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment