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