【问题标题】:Change focus and color when scroll cell in uitable滚动单元格时更改焦点和颜色
【发布时间】:2017-06-07 03:28:42
【问题描述】:

我在 swift 3 的 tvOS 项目中为我的 tableview 提供了此代码,我希望滚动时颜色单元格不聚焦!请你解释一下是怎么做的?

这是我的代码

func numberOfSections(in tableView: UITableView) -> Int {
    return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return tvChannelsArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
    
    // Show TV Channels names
    cell.textLabel?.text = ((tvChannelsArray[(indexPath as NSIndexPath).row] as AnyObject).object(forKey: "channel") as! String)
    
    cell.imageView?.image = UIImage(named: "\(cell.textLabel!.text!)")
    
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    channelsTableView.isHidden = false;

    return 100
    
}

【问题讨论】:

    标签: swift xcode uitableview cell


    【解决方案1】:

    在您的 tableview 委托中实现 UISsrollViewDelegate 方法ScrollViewDidScroll

        func scrollViewDidScroll(_ scrollView: UIScrollView) {
            for cell in tableView.visibleCells {
                if let currentCellPath = tableView.indexPath(for: cell),
                   let selectedCellPath = tableView.indexPathForSelectedRow {
                    guard currentCellPath != selectedCellPath else {
                        continue
                    }
                }
                let red = Float(cell.frame.origin.y / scrollView.contentSize.height)
                cell.contentView.backgroundColor = UIColor(colorLiteralRed: red, green: 0.5, blue: 0.25, alpha: 1)
            }
        }
    

    【讨论】:

    • tableView 说没找到怎么改呢?
    猜你喜欢
    • 2013-02-27
    • 1970-01-01
    • 1970-01-01
    • 2016-11-23
    • 1970-01-01
    • 2016-01-22
    • 2015-02-12
    • 2020-09-25
    • 1970-01-01
    相关资源
    最近更新 更多