チンペイペイペイ☆

iOSアプリ、大阪のカレー、子育て、iPhoneL♡VE部なブログ

[iOS][CocoaPods] MailboxのUIを実現するライブラリ「MCSwipeTableViewCell」



こんにちは。ちんぺい(@tinpay)です。

最近、CocoaPodsからいろいろ入れて試してみてるので、よさげなものを随時ご紹介していこうと思ってます。

今回は、Mailboxのようなリストを左右にスワイプするようなUIを実現させるライブラリ「MCSwipeTableViewCell」のご紹介です。

ss1-3

右にスワイプすると「完了」、さらに右にスワイプすると「削除」というようなUIが簡単に実装できます。

ss1-1

左スワイプで「時間指定」、「リスト登録」など、まさにMailbox!!

 どのくらいスライドすると最初のトリガー、2回目のトリガーか、スワイプの幅も割合で指定することができます。

 MCSwipeTableViewCell

git : https://github.com/alikaragoz/MCSwipeTableViewCell
License : MIT
CocoaPods : pod “MCSwipeTableViewCell”
Requirements : iOS >= 5.0 , ARC
Devloper : Ali Karagoz

TableCellを作成するところのカスタマイズなのですごく簡単です。

各アクションもBlocksで、見た目もシンプルでわかりやすい!

1- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
2    static NSString *CellIdentifier = @"Cell";
3 
4    MCSwipeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
5 
6    if (!cell) {
7        cell = [[MCSwipeTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
8 
9        //iOS7のSeparatorは途中で途切れてるので、それを両端まで伸ばす
10        if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
11        cell.separatorInset = UIEdgeInsetsZero;
12        }
13 
14        [cell setSelectionStyle:UITableViewCellSelectionStyleGray];
15 
16        cell.contentView.backgroundColor = [UIColor whiteColor];
17 
18    }
19    //処理イメージ設定
20    UIView *checkView = [self viewWithImageName:@"check"];
21    UIColor *greenColor = [UIColor colorWithRed:85.0 / 255.0 green:213.0 / 255.0 blue:80.0 / 255.0 alpha:1.0];
22 
23    UIView *crossView = [self viewWithImageName:@"cross"];
24    UIColor *redColor = [UIColor colorWithRed:232.0 / 255.0 green:61.0 / 255.0 blue:14.0 / 255.0 alpha:1.0];
25 
26    UIView *clockView = [self viewWithImageName:@"clock"];
27    UIColor *yellowColor = [UIColor colorWithRed:254.0 / 255.0 green:217.0 / 255.0 blue:56.0 / 255.0 alpha:1.0];
28 
29    UIView *listView = [self viewWithImageName:@"list"];
30    UIColor *brownColor = [UIColor colorWithRed:206.0 / 255.0 green:149.0 / 255.0 blue:98.0 / 255.0 alpha:1.0];
31 
32    //非アクティブ時の背景色
33    [cell setDefaultColor:self.mainTableView.backgroundView.backgroundColor];
34 
35    [cell.textLabel setText:@"左右スワイプする"];
36    [cell.detailTextLabel setText:@"右でチェック、削除。左でタイマー、リスト"];
37 
38    //右スワイプ1つ目(state:MCSwipeTableViewCellState1)
39    [cell setSwipeGestureWithView:checkView color:greenColor mode:MCSwipeTableViewCellModeSwitch state:MCSwipeTableViewCellState1 completionBlock:^(MCSwipeTableViewCell *cell, MCSwipeTableViewCellState state, MCSwipeTableViewCellMode mode) {
40        NSLog(@"Did swipe \"Checkmark\" cell");
41    }];
42    //右スワイプ2つ目(state:MCSwipeTableViewCellState2)
43    [cell setSwipeGestureWithView:crossView color:redColor mode:MCSwipeTableViewCellModeExit state:MCSwipeTableViewCellState2 completionBlock:^(MCSwipeTableViewCell *cell, MCSwipeTableViewCellState state, MCSwipeTableViewCellMode mode) {
44        NSLog(@"Did swipe \"Cross\" cell");
45        [self deleteCell:cell];
46    }];
47    //左スワイプ1つ目(state:MCSwipeTableViewCellState3)
48    [cell setSwipeGestureWithView:clockView color:yellowColor mode:MCSwipeTableViewCellModeSwitch state:MCSwipeTableViewCellState3 completionBlock:^(MCSwipeTableViewCell *cell, MCSwipeTableViewCellState state, MCSwipeTableViewCellMode mode) {
49        NSLog(@"Did swipe \"Clock\" cell");
50    }];
51 
52    //左スワイプ2つ目(state:MCSwipeTableViewCellState4)
53    [cell setSwipeGestureWithView:listView color:brownColor mode:MCSwipeTableViewCellModeSwitch state:MCSwipeTableViewCellState4 completionBlock:^(MCSwipeTableViewCell *cell, MCSwipeTableViewCellState state, MCSwipeTableViewCellMode mode) {
54        NSLog(@"Did swipe \"List\" cell");
55    }];
56 
57    return cell;
58 
59}
1- (UIView *)viewWithImageName:(NSString *)imageName {
2    UIImage *image = [UIImage imageNamed:imageName];
3    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
4    imageView.contentMode = UIViewContentModeCenter;
5    return imageView;
6}

お試しあれ。

, , ,

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

次のHTML タグと属性が使えます: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>