[ iOS ] contentConfiguration: TableView์ ๊ธฐ๋ณธ Cell ์ฌ์ฉํ๊ธฐ (iOS 14+)
๊ณต๋ถ ๊ธฐ๋ก
UITableViewCell์ ์ปค์คํ ํ์ง ์๊ณ ๋ cell์ ๊ตฌ์ฑํ ์ ์๋๋ก ์ฌ๋ฌ ์ต์ ์ ์ ๊ณตํ๋ค. ๊ฐ์ฅ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ผ๋ก๋ UITableViewCell์ ํ๋กํผํฐ ์ค textLabel, detailTextLabel, imageView๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด์์ง๋ง, iOS 14 ์ดํ๋ถํฐ๋ ์ด ํ๋กํผํฐ๋ค์ Deprecated ๋์ด ๋ ์ด์ ์ฌ์ฉํ ์ ์๋ค. ์ด๊ฒ๋ค์ ๋์ฒดํ๋ ํ๋กํผํฐ๊ฐ ๊ฐ๋ฐ๋์๋๋ฐ, ๋ฐ๋ก contentConfiguration ์ด๋ค.
UIButton์์๋ ์ด์ ์ ์ฌํ ํ๋กํผํฐ์ธ configuration(iOS 15+)์ด ์๋ค. ๋ง์ Class๋ค์์ Configuration์ด ๋ฑ์ฅํ๋ ๊ฒ์ผ๋ก ๋ณด์ ๊ฐ๋ฐ์๊ฐ View ๊ตฌ์ฑ์ ํ ๊ฐ์ฒด๋ก ์ ๋ฆฌ๋๋ฉฐ ์ฌ์ฌ์ฉ์ด ๊ฐ๋ฅํ ํํ๋ก ๊ฐ๋ฐํ๋๋ก Apple์์ ๋ฐฉํฅ์ฑ์ ์ ์ํด์ฃผ๋ ๊ฒ ๊ฐ๋ค.
Deprecated ์์๋ ์ ๋์์๋ฏ์ด contentConfiguration์ ์ฌ์ฉ์ ๊ฐ๋จํ๋ค.
Deprecated
cell์ text๋ฅผ ๊ด๋ฆฌํ๊ธฐ ์ํด content configuration์ ๋์ ์ฌ์ฉํ์ธ์. ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๊ณต๋๋ list content configuration์ ์ฌ์ฉํ๊ธฐ ์ํด์๋ defaultContentConfiguration()๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋ฐํ๋ configuration์ text ํ๋กํผํฐ๋ฅผ ํตํด ์ด๊ธฐ text๋ฅผ ์ค์ ํ ์ ์์ผ๋ฉฐ, ์ด๋ฅผ cell์ ์ ์ฉํ๊ธฐ ์ํด์๋ cell์ contentConfiguration ํ๋กํผํฐ์ ํ ๋นํ๋ฉด ๋ฉ๋๋ค.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = UITableViewCell()
var content = cell.defaultContentConfiguration()
content.text = "\(indexPath.row + 1)" //์ ๋ชฉ text
content.secondaryText = "\(indexPath.row + 1)๋ฒ cell" //์ค๋ช
text
content.image = .init(systemName: "person.fill") //์ด๋ฏธ์ง
content.imageProperties.tintColor = .darkGray //์ด๋ฏธ์ง ์์
cell.contentConfiguration = content //cell์ configuration ์ ์ฉ
return cell
}
UITableViewCell.contentConfiguration
UITableViewCell.defaultContentConfiguaration
UITableViewCell.textLabel