TableViewCell: selection control

J.Noma·2022년 2월 8일
0

BackgroundView
cell.selectedBackgroundView라는 프로퍼티가 존재한다. 이것은 선택된 cell의 뒤에만 동적으로 배치되므로 배경색같은거 설정할때 활용된다

let backgroundView = UIView()
backgroundView.layer.cornerRadius = 10
backgroundView.backgroundColor = .systemBlue
selectedBackgroundView = backgroundView

그 외
cell.setSelected() 메서드를 override하여 제어할 수 있다

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)
    if selected {
		titleLabel.textColor = .white
		dateLabel.textColor = .white
		previewLabel.textColor = .white
	} else {
		titleLabel.textColor = .label
		dateLabel.textColor = .label
		previewLabel.textColor = .systemGray
	}
}
profile
노션으로 이사갑니다 https://tungsten-run-778.notion.site/Study-Archive-98e51c3793684d428070695d5722d1fe

0개의 댓글