gpt4 book ai didi

ios - Swift,Identing Table Views 每行缩进更多

转载 作者:行者123 更新时间:2023-11-28 07:48:58 24 4
gpt4 key购买 nike

What it looks like

我正在努力使每个字符的名称在每一行中缩进得越来越多,所以从左边开始,然后下一行向右缩进一点,然后下一行向右缩进一点。

我实在想不通为什么我不能一个一个地缩进我的标签。任何帮助表示赞赏。

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
var Dwarves = ["Sleepy", "Sneezy", "Bashful", "Dopy", "Grumpy", "Doc", "Happy", "Sad"]
var imagess = ["Sleepy", "Sneezy", "Bashful", "Dopy", "Grumpy", "Doc", "Happy", "Sad"]

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return Dwarves.count
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "customCell") as! CustomTableViewCell

cell.CellView.layer.cornerRadius = cell.CellView.frame.height / 2
cell.Label.text = Dwarves[indexPath.row]
cell.CharcterImage.image = UIImage(named:

imagess[indexPath.row])
cell.CharcterImage.layer.cornerRadius = cell.CharcterImage.frame.height / 2

return cell
}

func tableView(_ tableView: UITableView, indentationLevelForRowAt indexPath: IndexPath.) -> Int {

}
}

我尝试使用 indentationLevelforRowAt 但它似乎不起作用。

 import UIKit


class CustomTableViewCell: UITableViewCell {

@IBOutlet weak var CellView: UIView!
@IBOutlet weak var CharcterImage: UIImageView!
@IBOutlet weak var Label:UILabel!
@IBOutlet weak var TableView:UITableView!





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
}

最佳答案

一种原始的方法是在字符串前加上空格。这里我使用两个空格的缩进级别。

cell.Label.text = "\(String(repeating: " " , count: indexPath.row*2))\(Dwarves[indexPath.row])")

关于ios - Swift,Identing Table Views 每行缩进更多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50196402/

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