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

Uicolor hexcolor init #136

Closed
wants to merge 6 commits into from
Closed

Uicolor hexcolor init #136

wants to merge 6 commits into from

Conversation

freed0m266
Copy link

Checklist

  • Added tests (if applicable)

Martin Svoboda added 6 commits November 2, 2023 11:19
scanLocation and scanHexInt32 are deprecated from iOS 13.0
scanLocation and scanHexInt32 are deprecated from iOS 13.0
Copy link

github-actions bot commented Nov 2, 2023

@freed0m266 your pull request is missing a changelog!

}
convenience init(hexString: String) {
var hexSanitized = hexString.trimmingCharacters(in: .whitespacesAndNewlines)
hexSanitized = hexSanitized.replacingOccurrences(of: "#", with: "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To achieve this kind of change you can simply use the original 5 line solution and only adjust scanLocation based on whether the string has leading hash or not.

Comment on lines +27 to +48
var rgb: UInt64 = 0

var r: CGFloat = 0.0
var g: CGFloat = 0.0
var b: CGFloat = 0.0
let a: CGFloat = 1.0

let length = hexSanitized.count

guard Scanner(string: hexSanitized).scanHexInt64(&rgb) else {
self.init()
return
}

if length == 6 {
r = CGFloat((rgb & 0xFF0000) >> 16) / 255.0
g = CGFloat((rgb & 0x00FF00) >> 8) / 255.0
b = CGFloat(rgb & 0x0000FF) / 255.0
} else {
self.init()
}

Copy link

@babacros babacros Nov 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Hey, I agree with @olejnjak. By the way, comments are missing...and what about correct indentation? Is it just copy&paste from Stack Overflow? In the case of using ChatGPT, I would ask to add comments 🤔

Copy link

github-actions bot commented Dec 4, 2023

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label Dec 4, 2023
@github-actions github-actions bot closed this Dec 10, 2023
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.

3 participants