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

Variation on IBEnum? #594

Open
phimage opened this issue Oct 4, 2018 · 1 comment
Open

Variation on IBEnum? #594

phimage opened this issue Oct 4, 2018 · 1 comment

Comments

@phimage
Copy link
Member

phimage commented Oct 4, 2018

Just want to discuss about a potential feature.

Unfortunately I think we cannot do "Trait Variation" for "User Defined Runtime Attributes"
So when we define something, it is for all ipads and iphones

I make a little PoC using NSDataAsset, that can be variated

A data asset named mask
screenshot 2018-10-04 at 11 05 14

Inside I put just some text file with the wanted value of a maskType

  • iphone file contains: circle
  • ipad file contains: ellipse

Then in MaskType I add a code to parse NSDataAsset

public extension MaskType {
  init(string: String?) {
....
case "dataAsset":
      if let name = params[safe: 0],
        let dataAsset = NSDataAsset(name: name),
        let value = String(data: dataAsset.data, encoding: .utf8) {
        self.init(string: value)
      } else {
        self = .none
      }

And finally I use it on my view in storyboard like this
dataAsset(mask)

on iphone a circle
screenshot 2018-10-04 at 11 11 41

on ipad an ellipse
screenshot 2018-10-04 at 10 54 20

@JakeLin
Copy link
Member

JakeLin commented Oct 15, 2018

@phimage Sorry, I didn't see your issue before, add another case is a great idea to support traits. Is it possible to add a case to support UITraitCollection and the original MaskType, then we can do it in the code without another asset file? That may help the users use it easier. And BTW: your example looks very good 👍

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