当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - 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?

网友答案:

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
    }
}
网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: