UITableViewCell with image on the right?

前端 未结 11 1089
南方客
南方客 2020-12-13 05:48

Is there a way to set the UITableViewCell.image to display on the right hand side of the cell instead of the left? Or will I need to add a separate UIImageView on the right

11条回答
  •  清歌不尽
    2020-12-13 06:44

    There is a way to set the position programmatically. Here is the Swift version of the solution:

    image.frame = CGRect.init(
    x: self.view.frame.width - image.frame.width*1.1,
    y: image.frame.origin.y,
    width: image.frame.width,
    height: image.frame.height)
    

    This will position your image on the right side of the cell. This solution is adjusting automatically the position according to screen size. The only down side is when you rotate the device you need to reload your data, but you can just override in your UITableView class the didRotate listener method:

    override func didRotate(from fromInterfaceOrientation: UIInterfaceOrientation) {
        _tableView.reloadData()}
    

提交回复
热议问题