gpt4 book ai didi

swift - 以编程方式更改 UIImage 位置

转载 作者:行者123 更新时间:2023-11-30 10:49:53 27 4
gpt4 key购买 nike

我有一个带有部分的 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

最佳答案

您只需在 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 ,也可以应用于 UIButton。

关于swift - 以编程方式更改 UIImage 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54828150/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com