klazuka / Kal

A calendar component for the iPhone (the UI is designed to match MobileCal)
http://www.thepolypeptides.com
1.22k stars 345 forks source link

Appearance customization #72

Closed groue closed 7 years ago

groue commented 11 years ago

Hi. Thanks for your Kal library.

I had to customize the grid appearence.

This has involved changing images in Kal.bundle (uncovered by these commits), introducing a backgroundView property of KalGridView, and having KalTileView conform to the UIAppearanceContainer protocol.

My goal was to be able to write code like:

@implementation MyViewController

+ (void)initialize
{
    id kalTileViewAppearance = [KalTileView appearanceWhenContainedIn:self, nil];

    UIColor *todayTextColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Kal.bundle/kal_tile_text_fill.png"]];
    [kalTileViewAppearance setTextColor:[UIColor colorWithWhite:0.7 alpha:1]   forState:KalTileStateAdjacent];
    [kalTileViewAppearance setTextColor:[UIColor whiteColor]                   forState:KalTileStateAdjacent | KalTileStateSelected];
    [kalTileViewAppearance setTextColor:todayTextColor                         forState:KalTileStateToday];
    [kalTileViewAppearance setTextColor:[UIColor whiteColor]                   forState:KalTileStateToday | KalTileStateSelected];

    [kalTileViewAppearance setShadowColor:[UIColor whiteColor]                 forState:KalTileStateToday];
    [kalTileViewAppearance setShadowColor:[UIColor colorWithWhite:0 alpha:0.2] forState:KalTileStateSelected];
    [kalTileViewAppearance setShadowColor:[UIColor colorWithWhite:0 alpha:0.2] forState:KalTileStateToday | KalTileStateSelected];

    [kalTileViewAppearance setReversesShadow:YES                               forState:KalTileStateSelected];
}

@end

Let me know if you're interested.

briancordanyoung commented 11 years ago

Awesome! I merged your changes with my fork.

It also has a KalImageManager class from this fork and I refactored to modern Obj-c and ARC.

In your example code you have a number of enum 'State' values. Those aren't defined anywhere. I'm just getting in to the UIApearence API, so this might be a simple thing... But, I don't see where the Kal code would use these values. Have you committed all your code? It there more to come?

Thanks. -Brian

briancordanyoung commented 11 years ago

Ooooops. My fail. I'm still getting used to GitHub. I didn't have all the work you did. I'm merging it now.

briancordanyoung commented 11 years ago

I'm going to go in and try to fix the bugs, but the current commits of pierlis/Kal has some problems. If you run the Holliday app and flip through a few months, you find that many days are miss numbered and treated from a previous/next month, when they are in the current month.

I'll let you all know when I have it working bug free. (If I'm misunderstanding something, let me know)

groue commented 11 years ago

I didn't expect appearance to alter day numbering... I'm happy those commits help you !

briancordanyoung commented 11 years ago

I might have been going cross eyed yesterday, because I can't reproduce the mis-numbering... But, the appearance was definitely not working correctly. I would fork your code and submit a pull request, but I'm still learning github. I don't see how to fork the same project from 2 people and submit code back.

I tracked the bug down to this one line of code: KalTileView.m: - (KalTileState)state { return *(int *)(&flags); }

That isn't giving you the result you want. My code is verbose and surely a math wiz could condense it,but this replacement does work:

- (KalTileState)state
{

    KalTileState currentState = KalTileStateNormal;

    if (flags.selected) currentState = (currentState | KalTileStateSelected);
    if (flags.highlighted) currentState = (currentState | KalTileStateHighlighted);
    if (flags.marked) currentState = (currentState | KalTileStateMarked);
    if (flags.type == KalTileTypeAdjacent) currentState = (currentState | KalTileStateAdjacent);
    if (flags.type == KalTileTypeToday) currentState = (currentState | KalTileStateToday);
    if (flags.type == (KalTileTypeAdjacent | KalTileTypeToday))
    {
        currentState = (currentState | KalTileStateAdjacent | KalTileStateToday);
    }

    //KalTileState oldWayToCalculateState = *(int *)(&flags);
    //NSLog(@"KalTileState Old: %d   New: %d", oldWayToCalculateState, currentState );

    return currentState;
}