IOS: Modify the delete button of TableView, iostableview

Source: Internet
Author: User

IOS: Modify the delete button of TableView, iostableview
Rewrite before iOS 6

-(Void) willTransitionToState :( UITableViewCellStateMask) state. It is found that the previous method of iOS7 does not work.


Under iOS7

Rewrite in custom cell

-(Void) willTransitionToState :( UITableViewCellStateMask) state {

[SuperwillTransitionToState: state];

If (state & UITableViewCellStateShowingDeleteConfirmationMask) = UITableViewCellStateShowingDeleteConfirmationMask ){

// [Self recurseAndReplaceSubViewIfDeleteConfirmationControl: self. subviews];

[Self defined mselector: @ selector (recurseAndReplaceSubViewIfDeleteConfirmationControl :) withObject: self. subviewsafterDelay: 0];

}

}


-(Void) recurseAndReplaceSubViewIfDeleteConfirmationControl :( NSArray *) subviews {

NSString * delete_button_name = @ "delete ";

For (UIView * subviewin subviews)

{

/**

* Before iOS 6

*/

If ([NSStringFromClass ([subviewclass]) isEqualToString: @ "UITableViewCellDeleteConfirmationControl"])

{

/**

Add a view to overwrite the default control. The image used has a transparent background.

*/

UIView * backgroundcoverdefacontrol control = [[UIViewalloc] initWithFrame: CGRectMake (0, 0, 64, 33)];

[BackgroundCoverDefaultControl setBackgroundColor: [UIColorwhiteColor];

[[Subview. subviews objectAtIndex: 0] addSubview: backgroundCoverDefaultControl];

UIImage * deleteImage = [UIImageimageNamed: delete_button_name];

UIImageView * deleteBtn = [[UIImageViewalloc] initWithFrame: CGRectMake (0, 0, deleteImage. size. width, deleteImage. size. height)];

[DeleteBtn setImage: [UIImageimageNamed: delete_button_name];

[[Subview. subviews objectAtIndex: 0] addSubview: deleteBtn];

}

/**

* Ios7

*/

If ([NSStringFromClass ([subviewclass]) isEqualToString: @ "UITableViewCellDeleteConfirmationButton"])

{

UIButton * deleteButton = (UIButton *) subview;

[DeleteButton setImage: [UIImageimageNamed: delete_button_name] forState: UIControlStateNormal];

[DeleteButton setTitle: @ "" forState: UIControlStateNormal];

[DeleteButton setBackgroundColor: [UIColorclearColor];

For (UIView * viewin subview. subviews ){

If ([view isKindOfClass: [UILabelclass]) {

[View removeFromSuperview];

}

}

}

If ([NSStringFromClass ([subviewclass]) isEqualToString: @ "UITableViewCellDeleteConfirmationView"])

{

For (UIView * innerSubViewin subview. subviews ){

If (! [InnerSubView isKindOfClass: [UIButton class]) {

[InnerSubView removeFromSuperview];

}

}

}

If ([subview. subviewscount]> 0 ){

[SelfrecurseAndReplaceSubViewIfDeleteConfirmationControl: subview. subviews];

}

}

}



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.