Commit 27ea4ba1 by Daniel Dahan

master: fixed UIImage context issue when creating translucent image

parent 7e8a98ad
...@@ -131,10 +131,20 @@ extension UIImage { ...@@ -131,10 +131,20 @@ extension UIImage {
- Returns: A UIImage that is the color passed in. - Returns: A UIImage that is the color passed in.
*/ */
open class func image(with color: UIColor, size: CGSize) -> UIImage? { open class func image(with color: UIColor, size: CGSize) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, false, Screen.scale)
guard let context = UIGraphicsGetCurrentContext() else {
return nil
}
context.scaleBy(x: 1.0, y: -1.0)
context.translateBy(x: 0.0, y: -size.height)
context.setBlendMode(.multiply)
let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height) let rect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
UIGraphicsBeginImageContextWithOptions(size, false, 0)
color.setFill() color.setFill()
UIRectFill(rect) context.fill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext() let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext() UIGraphicsEndImageContext()
return image?.withRenderingMode(.alwaysOriginal) return image?.withRenderingMode(.alwaysOriginal)
......
...@@ -287,13 +287,12 @@ open class NavigationBar: UINavigationBar { ...@@ -287,13 +287,12 @@ open class NavigationBar: UINavigationBar {
*/ */
open func prepare() { open func prepare() {
barStyle = .black barStyle = .black
isTranslucent = false
depthPreset = .depth1 depthPreset = .depth1
interimSpacePreset = .interimSpace3 interimSpacePreset = .interimSpace3
contentEdgeInsetsPreset = .square1 contentEdgeInsetsPreset = .square1
contentScaleFactor = Screen.scale contentScaleFactor = Screen.scale
backButtonImage = Icon.cm.arrowBack backButtonImage = Icon.cm.arrowBack
let image = UIImage.image(with: .clear, size: CGSize(width: 1, height: 1)) let image = UIImage.image(with: .clear, size: CGSize(width: bounds.width, height: bounds.height))
shadowImage = image shadowImage = image
setBackgroundImage(image, for: .default) setBackgroundImage(image, for: .default)
backgroundColor = .white backgroundColor = .white
......
...@@ -108,7 +108,8 @@ open class NavigationController: UINavigationController { ...@@ -108,7 +108,8 @@ open class NavigationController: UINavigationController {
open override func viewWillLayoutSubviews() { open override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews() super.viewWillLayoutSubviews()
navigationBar.width = view.width navigationBar.setNeedsLayout()
navigationBar.layoutIfNeeded()
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment