-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image manipulation & constraint improvements #15
Conversation
and edit them before activating
func withTintByMultiply(with color: UIColor) -> UIImage { | ||
defer { UIGraphicsEndImageContext() } | ||
|
||
UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer having the defer
immediately after BeginImageContext
.
let origin = CGPoint(x: (newWidth - size.width) / 2, y: (newHeight - size.height) / 2) | ||
draw(at: origin) | ||
let imageWithPadding = UIGraphicsGetImageFromCurrentImageContext() | ||
UIGraphicsEndImageContext() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a defer
here as well to avoid issues with early returns in the future.
|
||
let newHeight = size.height * 2 | ||
let newSize = CGSize(width: size.width, height: newHeight) | ||
UIGraphicsBeginImageContextWithOptions(newSize, false, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move defer
after beginContext
.
|
||
func transparentImageBackgroundTo(_ color: UIColor) -> UIImage { | ||
defer { UIGraphicsEndImageContext() } | ||
UIGraphicsBeginImageContextWithOptions(size, false, scale) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move defer
after beginContext
.
return newImage | ||
} | ||
|
||
func transparentImageBackgroundTo(_ color: UIColor) -> UIImage { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this? Couldn't you just set the UIImageView
's backgroundColor
?
import UIKit | ||
|
||
public extension UIImageView { | ||
class func autoLayout(image: UIImage?) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have similar issues with other views as well. Maybe we should just extend UIView
with
func autoLayout() {
translatesAutoresizingMaskIntoConstraints = false
return self
}
That way you could initialize your image view like let imageView = UIImageView(image: ...).autoLayout()
.
Code Climate has analyzed commit c83eb88 and detected 0 issues on this pull request. View more on Code Climate. |
Thanks for your feedback. I changed the stuff as discussed. |
Bitte #16 auch noch gleich anschauen und mit beiden eine neue Version pushen. Danke tausig.