mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
796 B
Swift
31 lines
796 B
Swift
7 years ago
|
//
|
||
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import Foundation
|
||
|
|
||
|
extension UIImage {
|
||
|
|
||
|
private func image(with view: UIView) -> UIImage? {
|
||
|
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.isOpaque, 0.0)
|
||
|
defer { UIGraphicsEndImageContext() }
|
||
|
|
||
|
guard let context = UIGraphicsGetCurrentContext() else {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
view.layer.render(in: context)
|
||
|
let image = UIGraphicsGetImageFromCurrentImageContext()
|
||
|
return image
|
||
|
}
|
||
|
|
||
|
@objc
|
||
|
public func templated(color: UIColor) -> UIImage? {
|
||
|
let template = self.withRenderingMode(.alwaysTemplate)
|
||
|
let imageView = UIImageView(image: template)
|
||
|
imageView.tintColor = color
|
||
|
|
||
|
return image(with: imageView)
|
||
|
}
|
||
|
}
|