私はSwift 3、Xcode 8.2を使用しています。Swift - 空の表のセルを表示するビューをカスタマイズする
空白のテーブルビューセルを表示するためのラベルがない場合は、これをカバーするラベルを作成できました。
私のコードは以下の通りであり、サブタイプはUITableViewController
です。
override func numberOfSections(in tableView: UITableView) -> Int {
// if there are scans to display...
if items.count > 0 {
tableView.backgroundView = nil
tableView.separatorStyle = .singleLine
return 1
}
else { // otherwise, return 0, remove cell lines, and display a Label
let rect = CGRect(x: 0,
y: 0,
width: tableView.bounds.size.width,
height: tableView.bounds.size.height)
let noScanLabel: UILabel = UILabel(frame: rect)
noScanLabel.text = "No Scans"
noScanLabel.textColor = UIColor.gray
noScanLabel.font = UIFont.boldSystemFont(ofSize: 24)
noScanLabel.textAlignment = NSTextAlignment.center
tableView.backgroundView = noScanLabel
tableView.separatorStyle = .none
return 0
}
}
これは結果です。
正常に見えます。しかし、どのようにして、私は、上がった中央のボタンを指している下向きの矢印を持つ別のテキスト行を含めるようにしますか? 「スキャンを開始するにはここをクリック」のようなものがありますか?
noScanLabel.text
フィールドに改行文字を追加しようとしましたが、問題が解決しませんでした。正しい方向のポインタがあれば助かります。
詳細を教えてください。 – noblerare