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

Card image for custom card type #75

Open
ThibaultKlein opened this issue Aug 1, 2016 · 2 comments
Open

Card image for custom card type #75

ThibaultKlein opened this issue Aug 1, 2016 · 2 comments

Comments

@ThibaultKlein
Copy link
Contributor

Hi there,

Is there an easy way to provide a custom image for a custom card type?

I noticed that I could "hack" by having the card image name equal to the card type name, but imageForCardType is using self as the bundle, which returns nil if the image is contained in the project bundle and not the pod bundle.

public func imageForCardType(cardType: CardType) -> UIImage? {
    return UIImage(named: cardType.name, inBundle: self, compatibleWithTraitCollection: nil)
}

Thank you for your help!

@DannyVancura
Copy link
Contributor

Hey! You should be able to implement and provide a CardTypeImageStore for a CardTextField yourself.
This should be possible by either:

  • copying the images from Caishen to your main bundle and setting NSBundle.mainBundle() as this image store
  • or by implementing the CardTypeImageStore protocol with something like:
func imageForCardType(cardType: CardType) -> UIImage? {
  switch cardType {
    case .YourCardType:
      return yourImage
    default:
      return NSBundle(forClass: CardTextField.self).imageForCardType(cardType)
  }
}

@ThibaultKlein
Copy link
Contributor Author

Thank you @DannyVancura, it works if I do your solution, although I still think there should be a way to provide a custom image without duplicating assets in our project. Ideally, we would like to specify the image in the card type model so it's trivial to create a new card type and provide all the structure you want at the same place. Let me know your thoughts on that!

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

No branches or pull requests

2 participants