Skip to content

Instantly share code, notes, and snippets.

@timd
Created February 15, 2012 12:41
Show Gist options
  • Save timd/1835423 to your computer and use it in GitHub Desktop.
Save timd/1835423 to your computer and use it in GitHub Desktop.
initWithStyle:reuseidentifier:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
// Create the top view
_topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, 80)];
[_topView setBackgroundColor:[UIColor whiteColor]];
// Create the top label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 150, 40)];
[label setFont:[UIFont fontWithName:@"Zapfino" size:18]];
[label setTextColor:[UIColor blackColor]];
[label setText:@"Swipe me!"];
[_topView addSubview:label];
// Create the top image
UIImageView *pointImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"point"]];
CGFloat pointImageXposition = self.contentView.frame.size.width - 160;
[pointImage setFrame:CGRectMake(pointImageXposition, 18, 144, 44)];
[_topView addSubview:pointImage];
// Create the swipe view
_swipeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, 80)];
[_swipeView setBackgroundColor:[UIColor darkGrayColor]];
// Create the swipe label
UILabel *haveSwipedlabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 25, 200, 30)];
[haveSwipedlabel setFont:[UIFont fontWithName:@"GillSans-Bold" size:18]];
[haveSwipedlabel setTextColor:[UIColor whiteColor]];
[haveSwipedlabel setBackgroundColor:[UIColor darkGrayColor]];
[haveSwipedlabel setText:@"I've been swiped!"];
[_swipeView addSubview:haveSwipedlabel];
// Add views to contentView
[self.contentView addSubview:_swipeView];
[self.contentView addSubview:_topView];
// Create the gesture recognizers
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeRightInCell:)];
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeLeftInCell:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[self addGestureRecognizer:swipeRight];
[self addGestureRecognizer:swipeLeft];
// Prevent selection highlighting
[self setSelectionStyle:UITableViewCellSelectionStyleNone];
}
return self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment