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];
}
}
}