Skip to content
This repository has been archived by the owner on Jun 19, 2019. It is now read-only.

Quick How To's

David Nedrow edited this page Oct 19, 2017 · 7 revisions

Animating style updates

From Issue #65:

[UIView animateWithDuration:defaultAnimationDuration animations:^{
    [self.myButton cas_updateStyling];
}];

Loading images from remote URLs

From Issue #69

In the stylesheet:

MyView.myClass {
    background-image-path: "http://somewhere.com/images/icon.png"
}

In code, declare a property:

@interface MyView
@property (nonatomic) NSString* backgroundImagePath;
@end

Then override cas_updateStyling and use something like UIKit+AFNetworking to load the image:

@implementation MyView 
- (void)cas_updateStyling {
    [super cas_updateStyling]
    [self.imageView setImageWithURL:[NSURL URLWithString:self.backgroundImagePath]]
}
@end

Set a UIImageView subclass's contentMode property to aspect fit

From Issue #72

Enums cannot be automatically picked up by reflection in objc so anything which is an enum value uses a custom mapping. For contentMode mappings, see this code.


Accessing properties in an Objective-C Category

From Issue #73

See the Custom Views section of the documentation.


Enabling live reload under Swift

From Issue #94

Add the following to your app delegate application:didFinishLaunchingWithOptions: method:

if UIDevice.currentDevice().systemName.compare("iPhone Simulator") == .OrderedSame {
    let curFilePath = __FILE__
    let curFileDir = curFilePath.stringByDeletingLastPathComponent;
    let styleFilePath = curFileDir.stringByAppendingPathComponent("StyleSheets/stylesheet.cas")
    CASStyler.defaultStyler().watchFilePath = styleFilePath
}

Forcing offscreen view to restyle

From Issue #64

Call the following, replacing myView with your view:

[CASStyler.defaultStyler styleItem:myView];

Alternating styles for table view

From Issue #48

The way web devs did this before :nth-child was invented was to append a class of "even" to the even table rows and define the styles for .even in your CSS file. Could do the same with Classy and would be more in line with what I think is great about the separation between style and content that Classy provides. I can work up an example if you want more details.


Xcode langspec

From Issue #11

Classy-langspec