ios - Swift , Identing Table Views 每行缩进更多
问题描述
我正在努力做到这一点,所以每个字符的每个名称都会随着每一行越来越多地缩进,所以从左边开始,下一行向右移动一点,然后下一行向右移动一点。
我根本想不通为什么我不能一个一个地缩进我的标签。任何帮助表示赞赏。
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])")
推荐阅读
- node.js - 加载不和谐机器人的配置文件失败
- performance - 在非 gui 中运行 JMeter 脚本以生成具有随机名称的新报告而不删除以前的报告
- google-earth-engine - 如何找到索引的最小和最大像素值?
- three.js - THREE.JS 点云 - 单个点在表示的后部太近
- react-native - 用于更新 React-Native 应用程序的 Web 管理面板
- javascript - 如何使用 Javascript 将十进制数格式化为 x10 表示法?
- r - 编写创建列的 R 函数
- c++ - spawn 和 co_spawn 有什么区别?(提升阿西奥)
- angular - 使用 @angular/fire 将 Angular 通用应用程序部署到 firebase 时出错
- django - 未找到带有参数 '('',)' 的 'single' 的反向操作。尝试了 1 种模式:['(?P
[-a-zA-Z0-9_]+)/$']