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

exposes icon fontweight from SF Symbol #43

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

peterpme
Copy link

Exposes fontWeight

bold checkmark:
image

black checkmark:
image

ultralight checkmark:
image

@@ -21,10 +21,19 @@ enum AlertPreset: String, Enumerable {
case .spinner:
return .spinner
case .custom:
guard let image = UIImage.init( systemName: options?.icon?.name ?? "swift") else {
throw BurntError.invalidSystemName
let weight: UIImage.SymbolWeight
Copy link
Owner

Choose a reason for hiding this comment

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

what about:

let weight = try? toFontWeight(from: options?.icon?.fontWeight) ?? .regular

Copy link
Author

@peterpme peterpme Jun 17, 2024

Choose a reason for hiding this comment

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

i think i tried something like this earlier, but tried it again and got something like this:

let configuration = UIImage.SymbolConfiguration(weight: weight)

... value of optional type 'UIImage.SymbolWeight?' must be unwrapped to a value of type 'UIImage.SymbolWeight'

that being said, this worked. wdyt?

guard let weight = try? toFontWeight(from: options?.icon?.fontWeight) else {
    throw BurntError.invalidIconWeight
}

Copy link
Owner

Choose a reason for hiding this comment

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

did you try the exact code i gave? mine has a fallback to regular

Copy link
Owner

Choose a reason for hiding this comment

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

that being said, this worked. wdyt?

that code doesn't not work because it will throw if weight isn't given, but it's optional

Copy link
Author

Choose a reason for hiding this comment

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

yes, i ran the exact code, here's what the whole custom block looks like:

      case .custom:
        let weight = try? toFontWeight(from: options?.icon?.fontWeight) ?? .regular

        let configuration = UIImage.SymbolConfiguration(weight: weight)
         guard let image = UIImage(systemName: options?.icon?.name ?? "swift", withConfiguration: configuration) else {
            throw BurntError.invalidSystemName
        }

        return .custom(image.withTintColor(options?.icon?.color ?? .systemBlue, renderingMode: .alwaysOriginal))

with the same error (i just tried again)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants