简体   繁体   中英

Decrease UITableViewCell width and put custom button on the left

Is there any way to decrease the standard width of grouped UITableViewCell and put a custom button on the left side(outside of cell boundary)? I tried to change the cell size but it keeps same

替代文字

You are going to have to fake the editing mode. What I mean by that is that as AtomRiot said you have to subclass UITableViewCell so that when in editing mode you show the button you want on the left, outside the cell.

But first things first. To change the indentation level for your cells all you need to do is implement this delegate method for the UITableView

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath

So that takes care of it. Then in your UITableViewCell subclass all I would do is to implement the method

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {

which I assume is called when the table the cell belongs to has changed to editing mode. There I would fade in (or animate in any way you want) a button to appear on the left of your cell. I have done it inside a grouped-style cell but never on the outside. Give it a try!

You could subclass UITableCell and add your own custom views inside of it. I have not personally added a button inside one but it should work. It may get confused with the row selected call the tableview makes if you are implementing that.

Cocoanetics博客似乎有一个非常好的解决方案: http//www.cocoanetics.com/2010/03/how-to-shrink-cells/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM