Custom Tableviewcell Slide-by Delete button

Source: Internet
Author: User

Sometimes the customer will have some special requirements, change the Tableviewcell of the slide Delete button look is one of them, like this:

This effect is also not difficult, just need to rewrite the Layoutsubviews method in the custom cell, the specific code is as follows:

Modify the style of the delete mode

-(void) layoutsubviews

{

[Super Layoutsubviews];

For (UIView *subview in Self.subviews)

{

if ([SubView iskindofclass:nsclassfromstring (@ "Uitableviewcelldeleteconfirmationview")])

{

UIView *confirmview= (UIView *) [subview.subviews firstobject];

Change background color

Confirmview.backgroundcolor=[uicolor colorwithwhite:0.898 alpha:1.000];

For (UIView *sub in Confirmview.subviews)

{

Modify the word size, color, this method can modify the text style

/*

if ([Sub Iskindofclass:nsclassfromstring (@ "Uibuttonlabel")]) {

UILabel *deletelabel= (UILabel *) Sub;

Deletelabel.backgroundcolor = [Uicolor Redcolor];

Change the font size of the delete button

Deletelabel.font=[uifont BOLDSYSTEMFONTOFSIZE:20];

Change the text of the button to delete

[Email protected] "hehe";

}

*/

Add a picture

if ([Sub Iskindofclass:nsclassfromstring (@ "UIView")]) {

UIView *deleteview = Sub;

Uiimageview *imageview = [[Uiimageview alloc] init];

Imageview.image = [UIImage imagenamed:@ "Iconfont-zhuchang"];

Imageview.frame = CGRectMake (Cgrectgetmaxx (sub.frame)-58,-5, 30, 30);

[Deleteview Addsubview:imageview];

}

}

Break

}

}

}

So you can successfully change the red background Delete button to a custom image.

But careful little partner will find every time when you click on the button button will be a short time to appear in the white delete text, do not be afraid, we rewrite a method is good:

#pragma mark to change the delete button text (make text empty)

-(nsstring*) TableView: (uitableview*) TableView Titlefordeleteconfirmationbuttonforrowatindexpath: (nsindexpath*) Indexpath {

return @ "";

}

This will solve the problem.

Sometimes there will be a slide show two options requirements, this is also very simple, in-(Nsarray *) TableView: (UITableView *) TableView Editactionsforrowatindexpath: ( Nsindexpath *) Indexpath; add Uitableviewrowaction in the method, the specific people find out for themselves.

Custom Tableviewcell Slide-by Delete button

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.