Skip to content
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

Merged
merged 8 commits into from
Mar 10, 2021
Merged

Conversation

melbic
Copy link
Member

@melbic melbic commented Mar 5, 2021

Bitte #16 auch noch gleich anschauen und mit beiden eine neue Version pushen. Danke tausig.

@melbic melbic changed the title Image manipulation Image manipulation & constraint improvements Mar 9, 2021
@melbic melbic changed the title Image manipulation & constraint improvements Image manipulation & constraint improvments Mar 9, 2021
@melbic melbic changed the title Image manipulation & constraint improvments Image manipulation & constraint improvements Mar 9, 2021
func withTintByMultiply(with color: UIColor) -> UIImage {
defer { UIGraphicsEndImageContext() }

UIGraphicsBeginImageContextWithOptions(size, false, UIScreen.main.scale)
Copy link
Contributor

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()
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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().

@codeclimate
Copy link

codeclimate bot commented Mar 10, 2021

Code Climate has analyzed commit c83eb88 and detected 0 issues on this pull request.

View more on Code Climate.

@melbic
Copy link
Member Author

melbic commented Mar 10, 2021

Thanks for your feedback. I changed the stuff as discussed.

@melbic melbic merged commit cf0ec8e into develop Mar 10, 2021
@melbic melbic deleted the feature/image_tint branch March 10, 2021 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants