Skip to content

Instantly share code, notes, and snippets.

@simonnickel
simonnickel / UIView+Embed.swift
Last active July 13, 2021 05:41
Simple UIView extension to embed a view in a container.
extension UIView {
struct EmbedInsets {
let top: CGFloat?
let left: CGFloat?
let right: CGFloat?
let bottom: CGFloat?
init(top: CGFloat? = nil, bottom: CGFloat? = nil, left: CGFloat? = nil, right: CGFloat? = nil) {
self.top = top
pod "SNLInteractionTableView", "~> 1.3.0"
#pragma mark - SNLInteractionCell delegate
- (void)swipeAction:(SNLSwipeSide)swipeSide onCell:(SNLExampleTableViewCell *)cell {
// implement actions on successfull swipe gesture
if (swipeSide == SNLSwipeSideLeft) {
NSLog(@"Left on '%@'", cell.label.text);
}
else if (swipeSide == SNLSwipeSideRight) {
NSLog(@"Right on '%@'", cell.label.text);
[self performSegueWithIdentifier:@"detail" sender:self];
/*
// to override default/storyboard colors use:
self.colorBackground = [UIColor grayColor];
self.colorContainer = [UIColor whiteColor];
self.colorSelected = [UIColor greenColor];
self.colorToolbarBarTint = [UIColor blueColor];
self.colorToolbarTint = [UIColor greenColor];
self.colorIndicator = [UIColor redColor];
self.colorIndicatorSuccess = [UIColor greenColor];
self.colorCustomSeparatorTop = [UIColor whiteColor];
#pragma mark - SNLInteractionTableView delegate - Reorder
- (void)startedReorderAtIndexPath:(NSIndexPath *)indexPath {
// additional setup when reordering starts
NSLog(@"Reordering started");
}
// Update your data source when a cell is draged to a new position. This method is called every time 2 cells switch positions.
- (void)moveRowFromIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
// update DataSource when cells are switched
UIBarButtonItem *buttonA = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(buttonPressed:)];
buttonA.tag = 1;
UIBarButtonItem *buttonB = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(buttonPressed:)];
buttonB.tag = 2;
UIBarButtonItem *flexibleItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
[self setToolbarButtons: [NSArray arrayWithObjects:flexibleItem, buttonA, flexibleItem, buttonB, flexibleItem, nil]];
[self configureSwipeOn:SNLSwipeSideLeft
withCancelAnimation:SNLSwipeAnimationDefault
andSuccessAnimation:SNLSwipeAnimationSlideBack
andImage:[UIImage imageNamed:@"indicator"]
andImageOnSuccess:[UIImage imageNamed:@"indicator_success"]];
[self configureSwipeOn:SNLSwipeSideRight
withCancelAnimation:SNLSwipeAnimationDefault
andSuccessAnimation:SNLSwipeAnimationSlideOut
andImage:[UIImage imageNamed:@"indicator"]
self.colorBackground = [UIColor grayColor];
self.colorContainer = [UIColor whiteColor];
self.colorSelected = [UIColor greenColor];
self.colorToolbarBarTint = [UIColor blueColor];
self.colorToolbarTint = [UIColor greenColor];
self.colorIndicator = [UIColor redColor];
self.colorIndicatorSuccess = [UIColor greenColor];
self.colorCustomSeparatorTop = [UIColor whiteColor];
self.colorCustomSeparatorBottom = [UIColor grayColor];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
SNLExampleTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
// set cells delegate to connect swipe action method
cell.delegate = self;
// initialize colors, images and toolbar in your SNLInteractionCell subclass
// see SNLExampleTableViewCell.m
// configure example content