Skip to content

Instantly share code, notes, and snippets.

@eliaskg
Created March 21, 2011 13:13
Show Gist options
  • Save eliaskg/879431 to your computer and use it in GitHub Desktop.
Save eliaskg/879431 to your computer and use it in GitHub Desktop.
Button theming in Cappuccino
@implementation CPButton (MyCostumButton)
- (void)setCustomTheme
{
var normalColorNormal = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:[
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"controls/buttonNormalNormalLeft.png"] size:CGSizeMake(2, 24)],
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"controls/buttonNormalNormalMiddle.png"] size:CGSizeMake(1, 24)],
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"controls/buttonNormalNormalRight.png"] size:CGSizeMake(2, 24)]
] isVertical:NO]];
var normalColorHighlighted = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:[
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"controls/buttonNormalActiveLeft.png"] size:CGSizeMake(2, 24)],
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"controls/buttonNormalActiveMiddle.png"] size:CGSizeMake(1, 24)],
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"controls/buttonNormalActiveRight.png"] size:CGSizeMake(2, 24)]
] isVertical:NO]];
[self setValue:normalColorNormal forThemeAttribute:"bezel-color" inState:CPThemeStateNormal];
[self setValue:normalColorHighlighted forThemeAttribute:"bezel-color" inState:CPThemeStateHighlighted];
var defaultColorNormal = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:[
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"controls/buttonDefaultNormalLeft.png"] size:CGSizeMake(2, 24)],
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"controls/buttonDefaultNormalMiddle.png"] size:CGSizeMake(1, 24)],
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"controls/buttonDefaultNormalRight.png"] size:CGSizeMake(2, 24)]
] isVertical:NO]];
var defaultColorHighlighted = [CPColor colorWithPatternImage:[[CPThreePartImage alloc] initWithImageSlices:[
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"controls/buttonDefaultActiveLeft.png"] size:CGSizeMake(2, 24)],
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"controls/buttonDefaultActiveMiddle.png"] size:CGSizeMake(1, 24)],
[[CPImage alloc] initWithContentsOfFile:[[CPBundle mainBundle] pathForResource:"controls/buttonDefaultActiveRight.png"] size:CGSizeMake(2, 24)]
] isVertical:NO]];
[self setValue:defaultColorNormal forThemeAttribute:"bezel-color" inState:CPThemeStateDefault];
[self setValue:defaultColorHighlighted forThemeAttribute:"bezel-color" inState:CPThemeStateDefault|CPThemeStateHighlighted];
[self setValue:normalColorNormal forThemeAttribute:"bezel-color" inState:CPThemeStateDefault|CPThemeStateDisabled];
//[self setValue:[CPColor whiteColor] forThemeAttribute:"text-color" inState:CPThemeStateDefault];
// [self setValue:[CPColor colorWithHexString:@"161616"] forThemeAttribute:"text-shadow-color" inState:CPThemeStateDefault];
// [self setValue:[CPColor colorWithHexString:@"999999"] forThemeAttribute:"text-color" inState:CPThemeStateDefault|CPThemeStateDisabled];
// [self setValue:[CPColor colorWithHexString:@"eeeeee"] forThemeAttribute:"text-shadow-color" inState:CPThemeStateDefault|CPThemeStateDisabled];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment