UITableViewCell サンプル
サンプルで動作を確認 コピーペーストで確認できます。
// 表示する内容を作成
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// 再利用するセルを取得
// let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Cell")
// 用意されているデフォルトのセルスタイル
// (左)画像(右)テキスト
UITableViewCellStyle.Default
// (左)テキスト(右)サブテキスト
UITableViewCellStyle.Value1
// (左)サブテキスト(右)テキスト
UITableViewCellStyle.Value2
// (左)画像(右上)テキスト(右下)サブテキスト
UITableViewCellStyle.Subtitle
// セルのデフォルトのテキストラベルの設定
cell.textLabel!.text = "テキスト"
cell.textLabel!.textColor = UIColor.blueColor()
cell.textLabel!.font = UIFont.systemFontOfSize(12)
cell.textLabel!.textAlignment = NSTextAlignment.Left
// セルのデフォルトの詳細用テキストラベルの設定
cell.detailTextLabel!.text = "ラベルテキスト"
cell.detailTextLabel!.textColor = UIColor.yellowColor()
cell.detailTextLabel!.font = UIFont.systemFontOfSize(12)
cell.detailTextLabel!.textAlignment = NSTextAlignment.Right
// セルのデフォルトの画像を設定
cell.imageView!.image = UIImage(named: "image.png")
// セルのデフォルトのアクセサリーを設定
cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
// UITableViewCellAccessoryType.None
// UITableViewCellAccessoryType.DisclosureIndicator
// UITableViewCellAccessoryType.DetailDisclosureButton
// UITableViewCellAccessoryType.Checkmark
// UITableViewCellAccessoryType.DetailButton
// セル選択時のスタイルを設定
cell.selectionStyle = UITableViewCellSelectionStyle.Blue
// UITableViewCellSelectionStyle.None
// UITableViewCellSelectionStyle.Blue
// UITableViewCellSelectionStyle.Gray
// UITableViewCellSelectionStyle.Default
return cell
}
UITableViewCell 概要
テーブルセルを利用時に使用します。
テーブルセルのセルスタイルの種類
■ UITableViewCellStyle
// 用意されているデフォルトのセルスタイル // (左)画像(右)テキスト UITableViewCellStyle.Default // (左)テキスト(右)サブテキスト UITableViewCellStyle.Value1 // (左)サブテキスト(右)テキスト UITableViewCellStyle.Value2 // (左)画像(右上)テキスト(右下)サブテキスト UITableViewCellStyle.Subtitle
セルのデフォルトのアクセサリーの種類
■ UITableViewCellAccessoryType
UITableViewCellAccessoryType.None UITableViewCellAccessoryType.DisclosureIndicator UITableViewCellAccessoryType.DetailDisclosureButton UITableViewCellAccessoryType.Checkmark UITableViewCellAccessoryType.DetailButton
セル選択時のスタイルの種類
■ UITableViewCellSelectionStyle
UITableViewCellSelectionStyle.None UITableViewCellSelectionStyle.Blue UITableViewCellSelectionStyle.Gray UITableViewCellSelectionStyle.Default
おすすめの本
