Giter Site home page Giter Site logo

colorassetcatalog's People

Contributors

mkko avatar samrayner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

colorassetcatalog's Issues

What Color Space to use?

I followed the instructions but the loaded color is always white.

I've inserted a breakpoint after loading the color and the loaded object prints:
kCGColorSpaceModelRGB 1 1 1 1

When I define the Color Asset, do I need to take the color space or any other property in account?
This only happens in ios 9 or 10.

JSONDecoder doesn't decode the Contents.json file (returns nil)

I've got a set of colours in the file like this one:

{
  "info" : {
    "version" : 1,
    "author" : "xcode"
  },
  "colors" : [
    {
      "idiom" : "universal",
      "color" : {
        "color-space" : "srgb",
        "components" : {
          "red" : "1.000",
          "alpha" : "1.000",
          "blue" : "1.000",
          "green" : "1.000"
        }
      }
    }
  ]
}

When tracing through the method I can see that all is going well until it tries to JSON decode the file.
Are you able to see anything wrong with the above file that would give a reason as to why it's not working?

When I catch the JSONDecode error, this is what it shows:

typeMismatch(Swift.Double, Swift.DecodingError.Context(codingPath: [ColorAssetCatalog.ColorAssetCatalog.(CodingKeys in _DAE07DEB4F1D47BCAEDAF908209E6C48).colors, Foundation.(_JSONKey in _12768CA107A31EF2DCE034FD75B541C9)(stringValue: "Index 0", intValue: Optional(0)), ColorAssetCatalog.ColorAsset.(CodingKeys in _DAE07DEB4F1D47BCAEDAF908209E6C48).color, ColorAssetCatalog.ColorAsset.Color.(CodingKeys in _DAE07DEB4F1D47BCAEDAF908209E6C48).components, ColorAssetCatalog.ColorAsset.Color.Components.(CodingKeys in _DAE07DEB4F1D47BCAEDAF908209E6C48).alpha], debugDescription: "Expected to decode Double but found a string/data instead.", underlyingError: nil))

8-bit Hexadecimal format not working

I bumped into an issue where colors highly saturated when using 8-bit Hexadecimal format. From what it looks, the following color:

      "color" : {
        "color-space" : "srgb",
        "components" : {
          "red" : "0x00",
          "alpha" : "1.000",
          "blue" : "0xD0",
          "green" : "0xA0"
        }
      }

turns into (r: 0, g: 1, b: 1). It looks like that hexadecimal numbers are not supported. I'm planning on doing a pull request tonight, hopefully you're okay to merge it.

Can't find asset Color in framework bundle

Hi! I've using ColorAssetCatalog without any issue until I moved Colors.xcassets into a framework I've been working on: it looks like both the iOS11 asset color loader and ColorAssetCatalog are loading resources from the main bundle.

So, when you try to load an asset color by name UIColor(asset: "StatusOnline") the constructor returns nil.

One of the system UIColor constructors allows to load an asset color from a different bundle:
public init?(named name: String, in bundle: Bundle?, compatibleWith traitCollection: UITraitCollection?)

Can't use with NSAttributedString in iOS 10

Impossible using colors as attributes in attributed strings with UILabel (iOS 10).

Example:
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor(asset: "baseColor")]
Got error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UILabel: the use of CGColor for color properties or inside attributed strings is not supported.'

iOS9 and 10 backward compatibility not working

Hi,

Just wanted to report that the backward compatibility feature was sadly broken by recent versions of xcode. The *.xcassets folder are now compiled into a single assets.car file that is not openable.

So the following code in ColorAssetManager does not work anymore:

func asset(named name: String) -> ColorAsset? {
        guard let dir = (bundle ?? Bundle.main).resourceURL?.appendingPathComponent("\(catalogName).xcassets"),
            let files = try? FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil, options: []),
            let colorset = files.first(where: { $0.lastPathComponent == "\(name).colorset" }),
            let data = try? Data(contentsOf: colorset.appendingPathComponent("Contents.json")),
            let catalog = try? JSONDecoder().decode(ColorAssetCatalog.self, from: data)
            else {
                return nil
        }

The problematic line is :

let files = try? FileManager.default.contentsOfDirectory(at: dir, includingPropertiesForKeys: nil, options: [])

Because the folder does not exists

I tried to find a way to extract the colors from the .car file without success.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.