2
사용자 정의 셀이있는 콜렉션 뷰가 있습니다. 그리고 나는 셀이 뷰의 중앙에 위치 할 때 UILabel을 콜렉션 뷰에서 검은 색에서 붉은 색으로 어떻게 바꿀 수 있는지 생각하지 않습니다.중심 위치 일 때 UICollectionViewCell에 마스크를 추가하십시오.
사용자 정의 셀이있는 콜렉션 뷰가 있습니다. 그리고 나는 셀이 뷰의 중앙에 위치 할 때 UILabel을 콜렉션 뷰에서 검은 색에서 붉은 색으로 어떻게 바꿀 수 있는지 생각하지 않습니다.중심 위치 일 때 UICollectionViewCell에 마스크를 추가하십시오.
내가 생각할 수있는 가장 쉬운 방법 : 그래서보기 컨트롤러가있는 경우 UIScrollView
의 서브 클래스 (및 UITableViewDelegate
프로토콜 UIScrollViewDelegate
프로토콜에서 상속)입니다 UITableView
명심
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
tableView.delegate = self
tableView.dataSource = self
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 50
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = "Cell #\(indexPath.row)"
return cell
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if let tableView = scrollView as? UITableView {
for cell in tableView.visibleCells {
adjustCellColor(cell: cell)
}
}
}
func adjustCellColor(cell: UITableViewCell) {
let cellFrame = tableView.convert(cell.frame, to: view)
if cellFrame.contains(view.center) {
cell.textLabel?.textColor = UIColor.red
} else {
cell.textLabel?.textColor = UIColor.black
}
}
}
UITableView
에 대한 대표는 과 같은 UIScrollViewDelegate
메서드를 구현할 수 있습니다. 이 메서드는 테이블 뷰를 스크롤 할 때 호출됩니다. 보이는 셀을 모두 반복하고 셀이 뷰의 가운데에 있으면 텍스트 색상을 빨간색으로 설정하고 그렇지 않으면 검정색으로 설정합니다.
자세한 내용을보고 이미 시도한 내용 (코드)을 보여주십시오. – shallowThought