ClassyKit / Classy

Expressive, flexible, and powerful stylesheets for UIView and friends.
http://classykit.github.io/Classy/
MIT License
740 stars 77 forks source link

FEATURE REQUEST: Dynamic typefaces #74

Closed TheCoordinator closed 6 years ago

TheCoordinator commented 10 years ago

I'm at the stage of evaluating Classy to use for my project. It seems like a brilliant solution and given the fact that it's done by @cloudkite, the creator of Masonry, I'm being more and more encouraged to use this for my project as well.

There are a few issues which I'll post in separately which I'll think would be great improvements to this project.

As for this specific issue, Apple added dynamic type faces to their API in iOS 7 and seems like, a lot of apps are vastly using it. Using NSNotificationCenter in every controller to update the typefaces seems a bit hideous and if we're already using classy to set all the labels, textfields and buttons font in our apps, it seems to me that having that as a feature in Classy sounds like a better solution.

@cloudkite, would this be something that we can count on in the upcoming releases of Classy?

Would appreciate your feedback on this.

Thanks.

keithnorm commented 10 years ago

I think this is a pretty good suggestion and perhaps something that should be baked in, but in the meantime I can show you the trick I'm using to add in custom style properties. Well, it's not really a trick , it's just the beauty of Classy and Objective-C :) So, one way to do this would be to add a UILabel category that implements a setter method to set the dynamic type value. Generically speaking, say you implement a property, mySillyProperty, on a UILabel category. Then, if you do this in your stylesheet:

UILabel {
  my-silly-property: Any String
}

Classy will call setMySillyProperty: with the value @"Any String" (you can do a bit more monkey patching to make Classy convert the property argument to a specific type - like the way it converts "red" into a UIColor, but that's an aside). Basically Classy boils down to being a very clever and helpful DSL to call methods on UIView's. I think it's awesome because there's very little magic going on.

Here's a bit of a hacky version showing how you might do this for a dynamic type setting property https://gist.github.com/keithnorm/594c70831f8be9b21056. Again, I'm not saying this is the right way to go with this request, but it's a technique I've found to be very useful.

cloudkite commented 10 years ago

@peymankh yeah out of the box support for Dynamic Type would be useful. @keithnorm Nice example thanks!

dzindra commented 9 years ago

See #89

dnedrow commented 6 years ago

@peymankh , given the contribution by @dzindra, Classy supports dynamic fonts. Can this issue be closed?

dnedrow commented 6 years ago

Closing as Dynamic Type is now supported out of the box.