Use Swtableviewcell to get the effect of the right push option for cell in IOS7 Mail

Source: Internet
Author: User

Swtableviewcell is a third-party UITableViewCell subclass hosted on GitHub that provides the ability to swipe left and right with custom UIButton such as delete, more, which is similar to cell in a message in iOS7. GitHub Home: Https://github.com/CEWendel/SWTableViewCell

Example: Scene: If I want to do a tableview now, its cell is the effect of Swtableviewcell. ViewController.h
#import <UIKit/UIKit.h> #import <SWTableViewCell.h> @interface viewcontroller:uiviewcontroller< Uitableviewdatasource,uitableviewdelegate,swtableviewcelldelegate]]> @property (nonatomic, strong) UITableView * TableView; @end

Viewcontroller.m

#import "ViewController.h" @interface Viewcontroller () @property (nonatomic, strong) Nsmutablearray *dataarray;@    End@implementation viewcontroller-(void) viewdidload{[Super Viewdidload]; [Self initviews];} -(void) initviews{_dataarray = [Nsmutablearray arraywithobjects:@ "Shanghai", @ "Beijing", @ "Nanjing", @ "Hangzhou", @ "    HongKong ", @" Shenzhen ", nil];    _tableview = [[UITableView alloc] Initwithframe:cgrectmake (0, 0, 320, 640)];    _tableview.delegate = self;    _tableview.datasource = self; [Self.view Addsubview:_tableview];} #prama mark-uitableviewdelegate-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (        Nsindexpath *) indexpath{static NSString *cellidentifier = @ "Cell";        Swtableviewcell *cell = (Swtableviewcell *) [TableView dequeuereusablecellwithidentifier:cellidentifier]; if (cell = = nil) {cell = [[Swtableviewcell alloc] Initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:celli        Dentifier]; Cell.leftutiLitybuttons = [self leftbuttons];        Cell.rightutilitybuttons = [self rightbuttons];    Cell.delegate = self;        } Cell.textLabel.text = _dataarray[indexpath.row];    return cell; }-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (Nsinteger) section{return 4;}    -(Nsarray *) rightbuttons{nsmutablearray *rightutilitybuttons = [Nsmutablearray new];                                                [Rightutilitybuttons sw_addutilitybuttonwithcolor: [Uicolor colorwithred:0.78f green:0.78f blue:0.8f alpha:1.0]    title:@ "More"];                                                [Rightutilitybuttons sw_addutilitybuttonwithcolor: [Uicolor colorwithred:1.0f green:0.231f blue:0.188 alpha:1.0f]        title:@ "Delete"]; return rightutilitybuttons;}        -(Nsarray *) leftbuttons{nsmutablearray *leftutilitybuttons = [Nsmutablearray new]; [Leftutilitybuttons sw_addutilitybuttonwithcolor: [Uicolor colorwithred:0.07 green:0.75f blue:0.16f alpha:1.0] title:@ "LEFT1"];                                                [Leftutilitybuttons sw_addutilitybuttonwithcolor: [Uicolor colorwithred:1.0f green:1.0f blue:0.35f alpha:1.0]    title:@ "Left2"];                                                [Leftutilitybuttons sw_addutilitybuttonwithcolor: [Uicolor colorwithred:1.0f green:0.231f blue:0.188f alpha:1.0]    title:@ "Left3"];                                                [Leftutilitybuttons sw_addutilitybuttonwithcolor: [Uicolor colorwithred:0.55f green:0.27f blue:0.07f alpha:1.0]    title:@ "Left4"]; return leftutilitybuttons;} #pragma mark-swtableviewdelegate-(void) Swipeabletableviewcell: (Swtableviewcell *) cell  Didtriggerleftutilitybuttonwithindex: (nsinteger) index {switch (index) {case 0:nslog (@ "Check button            was pressed ");        Break            Case 1:nslog (@ "clock button is pressed");        Break          Case 2:  NSLog (@ "Cross button is pressed");        Break        Case 3:nslog (@ "list button is pressed");    Default:break;    }}-(void) Swipeabletableviewcell: (Swtableviewcell *) cell Didtriggerrightutilitybuttonwithindex: (NSInteger) Index {            Switch (index) {case 0:nslog (@ "+ button was pressed");        Break        Case 1: {NSLog (@ "Delete button is pressed");    } Default:break; }}-(void) didreceivememorywarning{[super didreceivememorywarning];} @end

Effect:

Note: If you want to use Swtableviewcell in your custom Tableviewcell, you will need to use Swtableviewcell.contentview when adding components to Swtableviewcell. Addsubview: Method, otherwise, when you swipe left or right, the added component does not slide with it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.