Dark dishes One of the changes UITableViewCell left slide the style and customization of the Delete button

Source: Internet
Author: User

In the daily development we may encounter the need to customize the UITableViewCell left slide Delete button style, there are many custom third-party online, but all too heavyweight, should be for us maybe we need very small, and do not want to import a third party, and then set a variety of a lot of properties, Too much trouble, then how to modify the system comes with it?

Maybe you say can't modify, million is not absolute, we have artifact reveal, as an iOS program ape, if you even reveal do not know or will not use you are too low, OK, we started our dark dishes.

First, let's look at the hierarchical relationship of the UITableViewCell left slide button under Reveal,

Let's see, this is a hierarchical relationship in the left-slip state of the cell.

1,cell There are two Subview, one is Uitableviewcelldeleteconfirmationview, this class we in Xcode can not find out, so we do not find

The other is the cell Contentview, this is our common cell.contentview, this is needless to say, we all know that

Let's analyze Uitableviewcelldeleteconfirmationview, he's a view, and his subspace is what we're looking for. Delete button,

We see _uitableviewcellactionbutton This category worry, we do not care about it, we think of him as a uibutton on the line, as a button that is good to do, how to change how to change, then we how to get this button, and see the dark dishes below

-(void) modifideletebtn{ for(UIView *subviewinchself.subviews) {if([SubView iskindofclass:nsclassfromstring (@"Uitableviewcelldeleteconfirmationview")]) {Subview.backgroundcolor=Kcolorblue;  for(UIButton *btninchsubview.subviews) {if([Btn Iskindofclass:[uibuttonclass]]) {Btn.backgroundcolor=Kcolorblue; }            }        }    }}

The child controls are traversed to find

And then how to change it,

This piece of code we're going to

Layoutsubviews is called in order to traverse it.

This one

How do we control the width of the uitableviewcelldeleteconfirmationview?

-(NSString *) TableView: (UITableView *) TableView Titlefordeleteconfirmationbuttonforrowatindexpath: (Nsindexpath * ) indexpath{    return@ " delete hahaha haha ";}

In the tableview of this agent control, and then inside the cell control our button to display the title, you can also set the image, you can also give it to remove, add our own definition of the view ah what,

The Delete button is added to the

Uitableviewcelldeleteconfirmationview This class corresponds to the view above, so you add the time to add to him, the layout size is set according to his frame, you can also add constraints. Interested students try



All right, today's dark food is over.

Dark dishes One of the changes UITableViewCell left slide the style and customization of the 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.