【问题标题】:Changing the UIImage position programmarically以编程方式更改 UIImage 位置
【发布时间】:2019-07-16 14:39:33
【问题描述】:

我有一个带有部分的 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自定义单元格并按照你的意愿设计它

标签: swift uiimage position


【解决方案1】:

您只需在 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

sharing this solution 的积分转到 liau-jian-jie,它也可以应用于 UIButton。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-12
    • 2011-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多