erichoracek / Motif

Lightweight and customizable stylesheets for iOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Recommended approach for styling tableview cells

mwkirk opened this issue · comments

Hi Eric, very impressive library; the stylesheets are particularly clean and elegant.

I'm looking at using Motif in a project and trying to determine the best way to style UITableViewCells. Before I reinvent the wheel poorly, I thought I'd see if you had any recommendations. I'm sure you've used Motif in projects with table views.

I've prototyped an applier for UITableViewController that sets the appearance of cells it contains. This works thus far, but it feels like I could be going down the wrong path. I need to develop solution(s) that handle both dynamic and static table views.

You've eschewed using UIAppearance, and I'd guess that's because you've had problems with it (it definitely has its quirks). Almost feels like Motif is partially a means to avoid UIAppearance 😉

Thanks!

Hi @mwkirk,

Thanks for the kind words. Sounds like we need another example project with table view styling.

For the time being I can briefly describe how I commonly do table view styling with Motif:

With respect to the theme itself I'd recommend something like:

UsersTheme.yaml

.ProfileCell:
    imageView: .RoundedBorderedImage
    textLabel: .H1Text
    detailTextLabel: .BodyText

And then, in the table view controller, I typically do:

UsersViewController.m

@interface UsersViewController ()

@property (nonatomic, readonly) id<MTFThemeApplier> themeApplier;

@end

@implementation UsersViewController

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = /* dequeue the cell */

    NSError *error;
    if (![self.themeApplier applyClassWithName:UsersThemeClasses.ProfileCell to:cell error:&error]) {
        NSLog(@"%@", error);
    }

    return cell;
}

@end

Unfortunately this isn't as elegant as applying theme classes to static views. However, it sounds like your UITableView applier may be an interesting approach—I'm definitely open to any ideas to make it better. Hope this helps!