iOS/STUDY
[iOS] cellRegistration: cell 배경색 바꾸기
느리님
2022. 4. 25. 17:42
컬렉션 리스트뷰를 사용하다가 cell의 배경색을 바꾸려고 했지만 backgroundColor를 바꾸는 것으로는 바뀌지 않았다.
cell.backgroundColor = .backgroundColor
해결방법
backgroundView를 배경색 view로 넣어주었더니 변경되었다.
let background: UIView = {
let view = UIView()
view.backgroundColor = .backgroundColor
return view
}()
cell.backgroundView = background
비슷한 방법으로 cell이 클릭된 것처럼 보이지 않게 하려면 selectedBackgroundView를 바꿔준다.
let selectedBackground: UIView = {
let view = UIView()
view.backgroundColor = .clear
return view
}()
cell.selectedBackgroundView = selectedBackground