Swift, Identing Table Views, каждая строка становится более отступом - PullRequest
0 голосов
/ 06 мая 2018

Как это выглядит

Я пытаюсь сделать так, чтобы каждое имя символов все больше и больше отступало с каждой строкой, поэтому слева, затем следующий ряд идет немного правее, а затем следующий ряд немного правее.

Я просто не могу понять, почему я не могу сделать отступ для своих ярлыков один за другим. Любая помощь приветствуется.

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
}

}

Ответы [ 2 ]

0 голосов
/ 06 мая 2018

Примитивный способ сделать это состоит в том, чтобы префикс строки с пробелами. Здесь я использую уровень отступа в два пробела.

cell.Label.text = "\(String(repeating: " " , count: indexPath.row*2))\(Dwarves[indexPath.row])")
0 голосов
/ 06 мая 2018

indentationLevelforRowAt позволяет отображать строки таблицы в формате иерархического / древовидного типа. Но вы хотите сделать отступ только для части вашей клетки. Поэтому я думаю, что вы должны играть со своими ограничениями.

Одним из возможных решений является создание ведущего ограничения для метки, а в методе cellForRowAt напишите что-то вроде этого:

cell.labelLeadingConstraint.constant = 5 * indexPath.row
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...