gpt4 book ai didi

ios - 如何更新单元格中的 View 框架

转载 作者:行者123 更新时间:2023-11-28 06:28:06 25 4
gpt4 key购买 nike

我有一个单元格,里面有 1 个标签。

我想要什么时候向左然后向右,然后向左,然后向右显示这个标签...

这是我的代码:

class CustomTableViewCell: UITableViewCell {

@IBOutlet weak var titleData: UILabel!

var data: String? {
didSet {
titleData.text = data ?? ""
if alternativeMode {
titleData.frame.origin.x = (row % 2 != 0) ? 200 : 0
} else {
titleData.frame.origin.x = 200
}
layoutSubviews()
}
}

var row: Int!
var alternativeMode = false

override func layoutSubviews() {
super.layoutSubviews()
}

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
self.selectionStyle = .none
}

}

但是这个标签没有显示alternative。

最佳答案

我已经用另一种方法解决了这个问题

class CustomTableViewCell: UITableViewCell {

@IBOutlet weak var titleData: UILabel!
@IBOutlet weak var titleDataTrailingConstraint: NSLayoutConstraint!

var data: String? {
didSet {
titleData.text = data ?? ""
}
}

var row: Int!
var alternativeMode = false

override func layoutSubviews() {
super.layoutSubviews()

if titleDataTrailingConstraint != nil {
let screenSizeWidth = UIScreen.main.bounds.width
if alternativeMode {
titleDataTrailingConstraint.constant = (row % 2 == 0) ? (screenSizeWidth - titleData.bounds.width - 80) : 10
} else {
titleDataTrailingConstraint.constant = 10
}
}
}

override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
self.selectionStyle = .none
}

}

关于ios - 如何更新单元格中的 View 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41208887/

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