Skip to content

Instantly share code, notes, and snippets.

@BlairDuncan
Created August 2, 2011 13:44
Show Gist options
  • Save BlairDuncan/1120202 to your computer and use it in GitHub Desktop.
Save BlairDuncan/1120202 to your computer and use it in GitHub Desktop.
@implementation myCustomView : CPView
{
CPTextField textfield1;
CPTextField textfield2;
CPTextField textfield;
CPImageView imageView;
}
- (void)initIfNeeded
{
var width = CGRectGetWidth([self bounds]),
height = CGRectGetHeight([self bounds]);
if(!imageView)
{
imageView = [[CPimageView alloc] initWithFrame:CGRectMake(0,0,80,80)];
}
if(!textField1)
{
textField1 = [[CPTextField alloc] initWithFrame:CGRectMake(84,0,400-84,14)];
[textField1 setAlignment:CPLeftTextAlignment];
[textField1 setVerticalAlignment:CPTopVerticalTextAlignment];
[textField1 setLineBreakMode:CPLineBreakByTruncatingTail];
[textField1 setTextColor:[CPColor colorWithCalibratedRed:93.0 / 255.0 green:93.0 / 255.0 blue:93.0 / 255.0 alpha:1.0]];
[textField1 setTextShadowColor:[CPColor colorWithCalibratedRed:225.0 / 255.0 green:255.0 / 255.0 blue:255.0 / 255.0 alpha:0.7]];
[textField1 setTextShadowOffset:CGSizeMake(1.0, 1.0)];
[textField1 setFont:[CPFont systemFontOfSize:11.0]];
}
else
[textField1 setFrame:CGRectMake(84,0,400-84,14)];
if(!textField2)
{
textField2 = [[CPTextField alloc] initWithFrame:CGRectMake(84,12,400-84,18)];
[textField2 setAutoresizingMask:CPViewMaxXMargin | CPViewMaxYMargin];
[textField2 setAlignment:CPLeftTextAlignment];
[textField2 setVerticalAlignment:CPTopVerticalTextAlignment];
[textField2 setLineBreakMode:CPLineBreakByTruncatingTail];
[textField2 setTextColor:[CPColor colorWithCalibratedRed:50.0 / 255.0 green:50.0 / 255.0 blue:50.0 / 255.0 alpha:1.0]];
[textField2 setTextShadowColor:[CPColor colorWithCalibratedRed:225.0 / 255.0 green:255.0 / 255.0 blue:255.0 / 255.0 alpha:0.7]];
[textField2 setTextShadowOffset:CGSizeMake(1.0, 1.0)];
[textField2 setFont:[CPFont boldSystemFontOfSize:12.0]];
}
else
[textField2 setFrame:CGRectMake(84,12,400-84,18)];
if(!textTextField)
{
textTextField = [[CPTextField alloc] initWithFrame:CGRectMake(84,26,400-84,height)];
[textTextField setAutoresizingMask:CPViewMaxXMargin | CPViewMaxYMargin];
[textTextField setAlignment:CPLeftTextAlignment];
[textTextField setVerticalAlignment:CPTopVerticalTextAlignment];
[textTextField setLineBreakMode:CPLineBreakByWordWrapping];
[textTextField setTextColor:[CPColor colorWithCalibratedRed:93.0 / 255.0 green:93.0 / 255.0 blue:93.0 / 255.0 alpha:1.0]];
[textTextField setTextShadowColor:[CPColor colorWithCalibratedRed:225.0 / 255.0 green:255.0 / 255.0 blue:255.0 / 255.0 alpha:0.7]];
[textTextField setTextShadowOffset:CGSizeMake(1.0, 1.0)];
[textTextField setFont:[CPFont systemFontOfSize:11.0]];
}
else
[textTextField setFrame:CGRectMake(84,26,400-84,height)];
if(![imageView superview])
[self addSubview:imageView];
if(![textField2 superview])
[self addSubview:textField2];
if(![textField1 superview])
[self addSubview:textField1];
if(![textTextField superview])
[self addSubview:textTextField];
}
- (void)setObjectValue:(id)activityObject
{
[self initIfNeeded];
var width = CGRectGetWidth([self bounds]),
height = CGRectGetHeight([self bounds]);
[imageView setRepresentedObject:activityObject.owner];
[textField2 setObjectValue:[activityObject.owner.url lastPathComponent]+ " ("+ activityObject.owner.firstName + " " + activityObject.owner.lastName + ")"];
[textField1 setObjectValue:humaneDate(jsDate)];
[textField1 setToolTip:[jsDate description]];
[textTextField setObjectValue:update_typeString];
[textTextField sizeToFit];
}
@end
@implementation myCustomView (CPCoding)
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super initWithCoder:aCoder];
if (self)
{
// textField2 = [aCoder decodeObjectForKey:"textField2Key"];
}
return self;
}
- (void)encodeWithCoder:(CPCoder)aCoder
{
[super encodeWithCoder:aCoder];
// [aCoder encodeObject:textField2 forKey:"textField2Key"];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment