以编程方式更改UIImage位置

时间:2019-02-22 13:26:22

标签: swift uiimage position

我有一个带有部分的UITableView。我在每个单元格中添加了一个UImage,但是它在左侧,如何更改它使其移到右侧?

这是我每个单元格的代码:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cells")
    cell?.textLabel?.text = data[indexPath.section].subType[indexPath.row]
    cell?.textLabel?.textAlignment = .right
    cell?.textLabel?.font = UIFont(name: "GESSTwoLight-Light", size: 15)
    cell!.isUserInteractionEnabled = false;
    cell!.imageView?.image = UIImage(named: "username.png")

    return cell!
}

This is my UITableView

1 个答案:

答案 0 :(得分:0)

您只需要在tableView(_:cellForRowAt:)方法中执行以下操作:

cell.transform = CGAffineTransform(scaleX: -1.0, y: 1.0)
cell.textLabel?.transform = CGAffineTransform(scaleX: -1.0, y: 1.0)
cell.imageView?.transform = CGAffineTransform(scaleX: -1.0, y: 1.0)

这将创建following

对于liau-jian-jie,贷方转到sharing this solution,也可以将其应用于UIButtons。

相关问题