UITableViewCell with image on the right?

前端 未结 11 1090
南方客
南方客 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:22

    Here is an example in Swift with the approach of using accessoryView:

    private let reuseIdentifier: String = "your-cell-reuse-id"
    
    // MARK: UITableViewDataSource
    
    func tableView(tableView:UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
      var cell : UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as? UITableViewCell
      if (cell == nil) {
        cell = UITableViewCell(style:UITableViewCellStyle.Subtitle, reuseIdentifier:reuseIdentifier)
      }
    
      cell!.textLabel!.text = "Hello"
      cell!.detailTextLabel!.text = "World"
      cell!.accessoryView = UIImageView(image:UIImage(named:"YourImageName")!)
      return cell!
    }
    

提交回复
热议问题