IOS Modify TableView's Delete button

Source: Internet
Author: User

Rewrite before iOS 6

-(void) Willtransitiontostate: (uitableviewcellstatemask) state, found that the previous method of IOS7 no use


IOS7 under

Rewrite in custom cell

-(void) Willtransitiontostate: (uitableviewcellstatemask) state{

[superwilltransitiontostate: state];

if(state &uitableviewcellstateshowingdeleteconfirmationmask) = = Uitableviewcellstateshowingdeleteconfirmationmask) {

[Self recurseAndReplaceSubViewIfDeleteConfirmationControl:self.subviews];

[ self performselector:@selector(Recurseandreplacesubviewifdeleteconfirmationcontrol :)withobject:self. subviews afterdelay:0];

}

}


-(void) Recurseandreplacesubviewifdeleteconfirmationcontrol: (nsarray*) subviews{

nsstring *delete_button_name = @ "delete";

for (UIView *subview in Subviews)

{

/**

* IOS 6 ago

*/

if ([nsstringfromclass([subviewclass]) Isequaltostring:@ "Uitableviewcelldeleteconfirmationcontrol"])

{

/**

A view will be added to override the default control used by the image has a transparent background

*/

UIView *backgroundcoverdefaultcontrol = [[UIViewalloc] initwithframe: CGRectMake(0,0,+) ];

[Backgroundcoverdefaultcontrol setbackgroundcolor: [uicolorwhitecolor]];

[[Subview. subviews objectatindex:0] addsubview: Backgroundcoverdefaultcontrol];

UIImage *deleteimage = [UIImageimagenamed:d elete_button_name];

uiimageview *deletebtn = [[uiimageviewalloc]initwithframe:cgrectmake (0,0, DeleteImage. Size. width, deleteimage. size. height)];

[Deletebtn setimage: [UIImageimagenamed:d elete_button_name];

[[Subview. subviews objectatindex:0] addsubview:d eletebtn];

}

/**

* iOS7

*/

if ([nsstringfromclass([subviewclass]) Isequaltostring:@ "Uitableviewcelldeleteconfirmationbutton"])

{

UIButton *deletebutton = (UIButton *) Subview;

[DeleteButton setimage: [UIImageimagenamed:d elete_button_name] forstate :uicontrolstatenormal];

[DeleteButton settitle:@ ""forstate:uicontrolstatenormal];

[DeleteButton setbackgroundcolor: [uicolorclearcolor]];

for (UIView* View in Subview. subviews) {

if ([View iskindofclass: [UILabelclass]]) {

[View Removefromsuperview];

}

}

}

if ([nsstringfromclass([subviewclass]) Isequaltostring:@ "Uitableviewcelldeleteconfirmationview"])

{

for (UIView* innersubview in Subview. subviews) {

if (! [Innersubview iskindofclass: [UIButton class]] {

[Innersubview Removefromsuperview];

}

}

}

if ([Subview. subviews Count] >0) {

[self recurseandreplacesubviewifdeleteconfirmationcontrol: Subview. subviews ];

}

}

}



IOS Modify TableView's 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.