티스토리 뷰

UITableViewCell 을 만들때 이미 만들어진 셀이 없는 경우 아래의 코드를 이용해서 cell을 만들 수 있다.

UITableViewCell(style: .subtitle, reuseIdentifier: "cell")

 

이때 style: _______ 부분을 보면 총 4가지의 옵션이 있는데 아래와 같다.

 

하나씩 어떤 모양인지 살펴보자

 

 

.default

< 더보기를 눌러 코드를 보세요 >

더보기
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
    if cell == nil {
        cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
    }
    var config = cell?.defaultContentConfiguration()
    config?.text = bts[indexPath.row]
    config?.secondaryText = names[indexPath.row]
    config?.image = UIImage(named: images[indexPath.row])
    config?.imageProperties.maximumSize.width = 200
    config?.imageProperties.maximumSize.height = 120
    cell?.contentConfiguration = config
    return cell!
}

.subtitle

< 더보기를 눌러 코드를 보세요 >

더보기
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
    if cell == nil {
        cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell")
    }
    var config = cell?.defaultContentConfiguration()
    config?.text = bts[indexPath.row]
    config?.secondaryText = names[indexPath.row]
    config?.image = UIImage(named: images[indexPath.row])
    config?.imageProperties.maximumSize.width = 200
    config?.imageProperties.maximumSize.height = 120
    cell?.contentConfiguration = config
    return cell!
}

.value1

< 더보기를 눌러 코드를 보세요 >

더보기
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
    if cell == nil {
        cell = UITableViewCell(style: .value1, reuseIdentifier: "cell")
    }
    var config = cell?.defaultContentConfiguration()
    config?.text = bts[indexPath.row]
    config?.secondaryText = names[indexPath.row]
    config?.image = UIImage(named: images[indexPath.row])
    config?.imageProperties.maximumSize.width = 200
    config?.imageProperties.maximumSize.height = 120
    cell?.contentConfiguration = config
    return cell!
}

.value2

< 더보기를 눌러 코드를 보세요 >

더보기
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCell(withIdentifier: "cell")
    if cell == nil {
        cell = UITableViewCell(style: .value2, reuseIdentifier: "cell")
    }
    var config = cell?.defaultContentConfiguration()
    config?.text = bts[indexPath.row]
    config?.secondaryText = names[indexPath.row]
    config?.image = UIImage(named: images[indexPath.row])
    config?.imageProperties.maximumSize.width = 200
    config?.imageProperties.maximumSize.height = 120
    cell?.contentConfiguration = config
    return cell!
}
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
글 보관함