ClassyKit / Classy

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

Can't set UIViewContentMode enum #72

Closed daniel-hall closed 6 years ago

daniel-hall commented 10 years ago

Here's a weird but frustrating one:

I'm trying to set a UIImageView subclass's contentMode property to aspect fit (UIViewContentModeScaleAspectFit) using a stylesheet.

All of the below fail and result in the enum value of UIViewContentModeScaleToFill (0) being applied instead:

content-mode: scale-aspect-fit content-mode: scaleAspectFit content-mode: scaleaspectfit content-mode: UIViewContentModeScaleAspectFit content-mode: 1

However, enum constants with less camel-cased words work just fine, e.g.:

content-mode: top-left

So I'm guessing this is something that happens when more than two camel-cased words are appended to the enum name when naming the constant? For example:

typedef NS_ENUM(NSInteger, MyEnumType) { MyEnumTypeOne, // works MyEnumTypeOneTwo, // works MyEnumTypeOneTwoThree, // will not work? };

Or maybe it's just based on the total length of the constant name? Any suggestions / workarounds since even using the integer value doesn't seem to work?

cloudkite commented 10 years ago

Sorry this is mainly due to lack of documentation!

Enums cannot be automatically picked up by reflection in objc so anything which is an enum value uses a custom mapping see

https://github.com/cloudkite/Classy/blob/master/Classy/Parser/CASStyler.m#L450

In this case looks like I abbreviated a few of them, Sorry for the confusion!

So the magic word you are looking for is aspectFit

daniel-hall commented 10 years ago

Ah yes - that was all I needed! Thanks for the tip :)

I'm really appreciating the flexibility of Classy so far. I wasn't able to get Pixate working as cleanly with some of the functionality I needed. So thumbs up and thanks for this great framework!

dnedrow commented 6 years ago

@daniel-hall , can this issue be closed?

dnedrow commented 6 years ago

Added answer to wiki how-to.