Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TableViewCell disclosure indicator position

I have a custom tableviewcell with the standard disclosure indicator positioned in the centre vertically by default. How can I move this standard disclosure indicator vertically like in the iOS mail app?

enter image description here

like image 772
spigen Avatar asked Dec 02 '22 14:12

spigen


2 Answers

You can adjust the position of the default accessory by subclassing your cell and finding the UIButton in the cell's subviews (which represents the indicator) and holding a reference to it. You can then simply update the frame of the accessoryButton in layoutSubviews or wherever you choose like so:

class CellSubclass: UITableViewCell {

    var accessoryButton: UIButton?

    override func awakeFromNib() {
        super.awakeFromNib()
        accessoryType = .DisclosureIndicator
        accessoryButton = subviews.flatMap { $0 as? UIButton }.first
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        accessoryButton?.frame.origin.y = 8
    }
}
like image 73
Ian Avatar answered Dec 07 '22 01:12

Ian


You can not move standard disclosure indicator vertically.

If you want to achieve this functionality, then you need to use your custom cell and use image of disclosure indicator and then you can set this image with button on where ever you want to place.

Or you can use view also as a accessory indicator and add as a subview of UITableViewCell

[cell.contentView addSubview:aView];

You can read more over here disclosure indicator

like image 37
Nik Avatar answered Dec 07 '22 01:12

Nik